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' );
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' );
Share
Improve this question
asked Feb 10, 2020 at 7:35
Grzes SlaniaGrzes Slania
1511 silver badge5 bronze badges
1
- Just add both variables inside banner_shortcode() {} function before return. – Chetan Vaghela Commented Feb 10, 2020 at 9:19
1 Answer
Reset to default 1Try 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' );