Auto Insert Content After Post

Many blogs at the end of posts offer their readers the ability to share, tweet or vote using social bookmarking sites, email the article to others, or anything else that the blog owner would like to say at the bottom of each post.

Many will hardcode it into the theme or post it each time on a new post, but you don’t have to do that anymore!

This short snippet will allow you to auto insert content at the end of a post, it takes place in your theme functions file so backup before you begin.

functions.php

function end_post($content) {
if(!is_feed() && !is_home()) {
$content.= "<h2>Enjoy this?</h2>";
$content.= "<p>Tweet about this post: etc...</p>";
}
return $content;
}
add_filter ('the_content', 'end_post');

This snippet has no functionality as it stands, so I have left it blank as the possibilities for it runs into the hundreds, simply just add the content like so:

$content.= "CONTENT HERE";

This snippet can save a lot of time so content does not have to be added manually to posts, and will keep your other theme files looking much tidier!

You Might Also Like