Site logo

Archived topic

Shortcode via Hook - trouble with conditional

3 replies · Started by Craig on September 22, 2016

Viewing posts 1–4 of 4

Hello,
I've added a Beaver Builder template shortcode to Inside Content Container, and it works great...

<?php echo do_shortcode( ' [fl_builder_insert_layout slug="nav-vianney-college-seminary" type="fl-builder-template"]' ); ?>

My problem is that I only want it to appear on pages attached to my custom taxonomy – called "sections".

I tried the following and it didn't work.

<?php if( has_term('section', 'section-vianney-college-seminary' ) ) : ?>
      echo do_shortcode( ' [fl_builder_insert_layout slug="nav-vianney-college-seminary" type="fl-builder-template"]' );
<?php endif; ?>

Any suggestions?

Thanks!

UPDATE...I got it working sort of...

I had to order incorrect in my php...

<?php if( has_term('section-vianney-college-seminary', 'section' ) ) : ?>
      echo do_shortcode( ' [fl_builder_insert_layout slug="nav-vianney-college-seminary" type="fl-builder-template"]' );
<?php endif; ?>

But...

Now it spits out echo do_shortcode( ' in html along before properly executing the shortcode.

Any suggestions?

OK...finally got it...

this worked...

<?php if( has_term('section-vianney-college-seminary', 'section' ) ) : ?>
    <?php  echo do_shortcode( ' [fl_builder_insert_layout slug="nav-vianney-college-seminary" type="fl-builder-template"]' );  ?>
<?php endif; ?>

I needed to wrap the echo do_shortcode line in php tags.

Glad you got it working! Thanks for sharing your code :)

This archived topic is closed to new replies.