[Resolved] Shortcode via Hook – trouble with conditional

Home Forums Support [Resolved] Shortcode via Hook – trouble with conditional

Home Forums Support Shortcode via Hook – trouble with conditional

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #228797
    Craig

    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!

    #228798
    Craig

    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?

    #228799
    Craig

    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.

    #228827
    Tom
    Lead Developer
    Lead Developer

    Glad you got it working! Thanks for sharing your code 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.