[Resolved] PHP filter with two conditionals

Home Forums Support [Resolved] PHP filter with two conditionals

Home Forums Support PHP filter with two conditionals

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #358091
    dale

    Hi. I added a Yummly button to recipe posts on one site using GP Hooks “After Entry Title.”

    <?php
    if ( in_category( 'food' ) )
    { ?>
     
    <a href="//yummly.com" rel="nofollow" class="YUMMLY-YUM-BUTTON">Yum</a>
    <script src="https://www.yummly.com/js/widget.js?wordpress"></script>
    
     
    <?php }
    ?>

    It looks great on the posts, but it’s also showing up on the category pages, which I don’t want it to. So I need to add the conditional

    if (( is_single() ))

    but I’m not sure where to put that. Would it be like

    if (( is_single() ) ( in_category( 'food' ) ))

    or should there be an “and” condition in there somewhere?

    #358142
    Tom
    Lead Developer
    Lead Developer

    Try this:

    <?php
    if ( in_category( 'food' ) && is_single() )
    { ?>
     
    <a href="//yummly.com" rel="nofollow" class="YUMMLY-YUM-BUTTON">Yum</a>
    <script src="https://www.yummly.com/js/widget.js?wordpress"></script>
    
     
    <?php }
    ?>
    #358267
    dale

    Thank you! It worked.

    #358446
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

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