Try it with something like this in your theme’s functions.php [untested]:
add_filter('the_content', 'custom_category_text');
function custom_category_text($content){
global $post;
$custom_category_text = '<p>Put your Custom category text here.</p>';
if(in_category('3')){ // change catetegory ID 3
$content = $content . $custom_category_text;
}
return $content;
}
Change the category ID in in_category('3')
to the correct category ID.
This has worked beautifully, THANK YOU!
You’re welcome. Glad you got it resolved.
Hi…this code working for me also…
Does anybody knows how i can add some diferent content in two diferent categories.
ex. i want to add “My name” at category “products”
and i want to add “website name ” at category “sales”
Thanks..
Hello,
I want to use this too! But I’m having trouble because I want the ‘text’ to include some code (a few div’s). It works great when its only text, but when I try to use a div I get an error.
Here is what I’m using:
add_filter('the_content', 'custom_category_text');
function custom_category_text($content){
global $post;
$custom_category_text = '<div class="alert alert-block">This is some text inside a DIV tag</div>';
if(in_category('3')){ // change catetegory ID 3
$content = $content . $custom_category_text;
}
return $content;
}
Any help very much appreciated!
Thanks,
Ben
@bennygill
Your code seems to work for me. What is the error you get?
I figured out what the problem was.
I had apostrophes as part of the text in the code —> ‘
Once I removed those it worked fine.