• Resolved ChrisStoneman

    (@chrisstoneman)


    I’d like to add the same piece of custom text to the bottom of every post in a certain category. How do I do this?

    I’ve tried using several plugins, ‘PostEnder’ almost works but doesn’t display the text on the homepage. ‘AddPostURL’ and ‘AddPostFooter’ add the text to all posts.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    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.

    Thread Starter ChrisStoneman

    (@chrisstoneman)

    This has worked beautifully, THANK YOU!

    Moderator keesiemeijer

    (@keesiemeijer)

    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

    Moderator keesiemeijer

    (@keesiemeijer)

    @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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding custom text to bottom of all posts in particular category’ is closed to new replies.