Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Creating a shortcode but need to define variable

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #271595
    amidigital
    Participant

    This seems to be working except I get this error message…

    “Notice: Undefined variable: template_url in /nas/content/live/agblogqa/wp-content/themes/agblog/functions.php on line 648”

    My attempt at defining $template_url on the top row.

    $template_url = "https://www.qa.apartmentguide.com";
    
    function senior_func( $atts ){
        print "<a href='{$template_url}/blog/wp-content/uploads/2018/05/Guide-Banner.jpg'>Link to Banner</a>";
    }
    add_shortcode( 'senior-guide', 'senior_func' );
    
    #271640
    tomnoble92
    Participant

    I’m no backend developer but isn’t $atts the function thats undefined. Your passing it into the function and it’s not assigned to anything.

    #271782
    chris_2080
    Participant

    use

    $atts = shortcode_atts(
            array(
                'template_url' => 'https://www.default-url.com',
            ), $atts
        );
    

    and simply supplying a value. for example [template_url=’https://www.qa.apartmentguide.com’%5D

    $template_url = "https://www.qa.apartmentguide.com";
    
    function senior_func( $atts ){
        $atts = shortcode_atts(
            array(
                'template_url' => 'https://www.default-url.com',
            ), $atts
        );
        print "<a href='{$template_url}/blog/wp-content/uploads/2018/05/Guide-Banner.jpg'>Link to Banner</a>";
    }
    add_shortcode( 'senior-guide', 'senior_func' );
    
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.