0

I am creating a shortcode that requires the use of two different variables $banner and $banner__feature. I know the variables are correct and they work because I tested them in another template file that I created. As for the short code only the HTML from the displays on the website but the variables do not. I don't know what I'm doing wrong here and I need the Variables to show.

$banner = esc_url( get_stylesheet_directory_uri() . '/images/banner.jpg' );

$banner__feature = esc_url( get_stylesheet_directory_uri() . '/images/banner__feature--easter.jpg' );

function banner_shortcode() {

return '<div class="banner banner--call-now" data-parallax="scroll" data-bleed="100" data-image-src="' . $banner . '"> 
    <div class="banner__left">
        <img class="img-responsive" src="' . $banner__feature . '">
    </div>
    <div class="banner__center">
        <h2 class="banner__title">Call Now!</h2>
        <h1 class="banner__phone"><strong><a href="tel:1-570-877-8595"><strong>570-877-8595</strong></a></strong></h1>
    </div>
    <div class="banner__right">
        <img class="img-responsive" src="' . $banner__feature . '">
    </div>
</div>';

}
add_shortcode( 'banner', 'banner_shortcode' );
1
  • Just add both variables inside banner_shortcode() {} function before return. Feb 10, 2020 at 9:19

1 Answer 1

1

Try this:

function banner_shortcode() {

    $banner = esc_url( get_stylesheet_directory_uri() . '/images/banner.jpg' );
    $banner__feature = esc_url( get_stylesheet_directory_uri() . '/images/banner__feature--easter.jpg' );

    return '<div class="banner banner--call-now" data-parallax="scroll" data-bleed="100" data-image-src="' . $banner . '"> 
        <div class="banner__left">
            <img class="img-responsive" src="' . $banner__feature . '">
        </div>
        <div class="banner__center">
            <h2 class="banner__title">Call Now!</h2>
            <h1 class="banner__phone"><strong><a href="tel:1-570-877-8595"><strong>570-877-8595</strong></a></strong></h1>
        </div>
        <div class="banner__right">
            <img class="img-responsive" src="' . $banner__feature . '">
        </div>
    </div>';

}
add_shortcode( 'banner', 'banner_shortcode' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.