[Resolved] Conditional code in hook

Home Forums Support [Resolved] Conditional code in hook

Home Forums Support Conditional code in hook

  • This topic has 10 replies, 4 voices, and was last updated 7 years ago by Leo.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #383640
    Aaron

    I’ve just started trying to write php and am trying to enter a shortcode after content for one category. Here’s what I have:

    <?php if ( is_category( 'hearing' ) ) : ?>
        <?php  echo do_shortcode( ' [elementor-template id=β€œ701”] ' );  ?>
    <?php endif; ?>

    But I cannot get it working.

    Any idea what I’m doing wrong?

    #383648
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Are you wanting it to show up after the single post content, or on the category archive page?

    #383649
    Aaron

    Hi Tom.

    Single posts only.

    Thanks for the quick response.

    #383652
    Tom
    Lead Developer
    Lead Developer

    Try this instead:

    <?php if ( in_category( 'hearing' ) ) : ?>
        <?php echo do_shortcode( '[elementor-template id="701"]' ); ?>
    <?php endif; ?>
    #383655
    Aaron

    That’s working now. But it’s also showing up on the archive page for that category.

    #383672
    Aaron

    Got it. Had to add && is_single().

    Phew. I really wish conditional statements were easier. Thanks, Tom.

    #384021
    Tom
    Lead Developer
    Lead Developer

    Glad I could help πŸ™‚

    #408753
    Mikel Mandon

    Hi Aaron or Tom, Could you please post the whole code with the && is_single() ammendement? Thanks !

    #408838
    Leo
    Staff
    Customer Support

    This should be it:

    <?php if ( in_category( 'hearing' ) && is_single() ) : ?>
        <?php echo do_shortcode( '[elementor-template id="701"]' ); ?>
    <?php endif; ?>
    #408929
    Mikel Mandon

    Hi thanks for the swift response πŸ˜€

    —-EDITED and opened a new topic—–

    Thanks for assistance
    Mikel

    #409179
    Leo
    Staff
    Customer Support

    Can you open a new topic for your questions? Thanks!

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