WordPress Tip: Insert Content automatically after each Post in wordpress
- By Viral Patel on August 19, 2009
- Tutorial
WordPress is a great blogging platform which is highly configurable. It allows you a lot of things to do with your Blog. For example, notice the Share Buttons at the end of this post. User can click on those buttons and share this article in any of their favorite social site. If you have subscribe for RSS feed for this blog, you may notice the same buttons at the end of the article in your RSS Reader.
So how to add content automatically after each Post? Simple, use WordPress Hooks to add Filters that add content. For example copy below code in functions.php file inside your theme folder.
function insertRSSFootNote($content) {
if(!is_feed() && !is_home()) {
$content.= "<div class='subscribe'>";
$content.= "<h4>Enjoyed this article?</h4>";
$content.= "<p>Subscribe to our <a href='http://viralpatel.net/blogs/feed'>RSS feed</a> and never miss a recipe!</p>";
$content.= "</div>";
}
return $content;
}
add_filter ('the_content', 'insertRSSFootNote');
The insertRSSFootNote() function in above code simply append any text in the $content variable.
Then, our insertRSSFootNote() function is hooked to the the_content() function, and it is automatically called every time the the_content is called. Using this function is basically the same as typing in the text at the end of each post.
Notice the (!is_feed) condition on line 2, which prevents the text from being inserted in the RSS feed. If you want the text to appear in your RSS feed, replace line 2 with the following:
if (!is_home()) {
Simply modify the code and add text of your choice at the end of each post in WordPress.
Happy Blogging…
Get our Articles via Email. Enter your email address.


