Auto Insert Content After Post

Snippets | By | 13 January 2011 | Comments 0

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!

Paul Maloney is a UK based web designer/developer and runs the design agency Tropica. He particularly enjoys using and working with WordPress and has a keen interest in typography. You can also follow Paul on Twitter.

Visit Paul Maloney's website

Be The First To Comment

Leave A Comment.