Archived topic
PHP filter with two conditionals
3 replies · Started by dale on August 1, 2017
Viewing posts 1–4 of 4
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?
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 }
?>
Thank you! It worked.
You're welcome :)
This archived topic is closed to new replies.