Display Custom Content After Posts From Some Specific Category In WordPress

Inserting custom content after each post can be done by adding a simple function in your theme’s function.php file or if you don’t like editing in your theme files and avoid feature lost after updates then use the Code Snippets plugin. In this tutorial we will explain you adding custom contnet after each post or after posts from some specific category in WordPress.

How To Add Custom Content After Post By Catgeory In WordPress?

Simply copy paste the following function in your theme’s function.php file replacing category id ‘3‘ to the id of your category and text ‘Your text here‘ with your own custom text you like adding after posts:

add_filter(‘the_content’, ‘custom_category_text’);

function custom_category_text($content){
global $post;
$custom_category_text = ‘<p>You text here<p/>’;
if(in_category(‘3’)){ // change catetegory ID 3
    $content =  $content . $custom_category_text;
}
return $content;
}

Tip: Reveal IDs is an easy plugin to find category, post, page and all other content IDs in WordPress.

How To Add Custom Content After Each & Every Post In WordPress?

Use the following code in your theme’s function.php file replacing ‘You text here‘ with your own custom text you like showing after posts and this time there is no need of adding any category ID

function add_post_content($content) {
    if(!is_feed() && !is_home()) {
        $content .= ‘<p>You text here</p>’;
    }
    return $content;
}
add_filter(‘the_content’, ‘add_post_content’);

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.