How to insert text into post based on category – via single.php file

I would like to show specific content within a post if the post is listed under a specific category.

For example, if we’re on the Dallas post and it is under the ‘Dallas’ category, then I want specific text to show on the Dallas page via a single.php code insert.

single.php

echo <<<insert
<?php if ( in_category( ‘dallas-slug’) ) : ?>
<p>
custom text to insert
</p>
<?php endif; ?>
insert;

Whenever I do this, it shows the text across all my post, ignoring the actual category slug. I’d like for the text to only show on posts where the ‘dallas-slug’ category is used.

Read more here:: How to insert text into post based on category – via single.php file

Leave a Reply

Your email address will not be published. Required fields are marked *