WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Need help with conditional statement to add content to certain category posts

[Resolved] Need help with conditional statement to add content to certain category posts

  • I’m trying to add some content to the end of each post’s content (and before comments) but only if that post is in a particular category (category “XYZ”).

    Here’s the conditional code that I’ve come up with (in my very limited capabilities) in my functions.php file, but it’s not outputting anything after the content in category XYZ posts.

    Any ideas where I’ve gone wrong? Or, any better way of writing the code?

    function add_post_content($content) {
    	if(is_single() && is_category('XYZ')) {
    		$content .= 'This is the text that will automatically get inserted after the post if it's in category XYZ.';
    	}
    	return $content;
    }
    add_filter('the_content', 'add_post_content');
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Need help with conditional statement to add content to certain category posts’ is closed to new replies.