Snippets

WordPress: Add Content After Post Automatically

WordPress Add Content After Post Automatically – If you are a WordPress theme developer, at some point of time or other, you may have wanted to add content after post automatically. Here is a neat snippet that let’s you do exactly that with just few lines of code.

WordPress Add Content After Post Automatically

The solution provided here does not require you to edit the actual theme files. Simply copy the following code in the functions.php file of your theme, write the content that you want to be shown and you are done.

function insert_custom_content($content)
{
if(!is_feed() && !is_home()) {
$content.= "<div class='custom_content'>";
$content.= "<h3>Some heading</h3>";
$content.= "<p>This is a custom content that appears at the end of every article.</p>";
$content.= "</div>";
}

return $content;
}
add_filter ('the_content', 'insert_custom_content');

Very simple, isn’t it?

That’s it!

Do you know of any other ways to add content after post automatically in WordPress? Feel free to share your suggestions by commenting below.

Share your thoughts, comment below now!

*

*