
Most blogs automatically displays some text after each post, for exemple to ask readers to subscribe to their rss feed. This text is very often hardcoded. Why not using function.php instead, and be able to keep the text when you’ll switch theme?

Most blogs automatically displays some text after each post, for exemple to ask readers to subscribe to their rss feed. This text is very often hardcoded. Why not using function.php instead, and be able to keep the text when you’ll switch theme?
To achieve this recipe, simply paste the following code in your functions.php file. By using functions.php, you'll not have to re-insert this code if you switch themes.
function insertFootNote($content) {
if(!is_feed() && !is_home()) {
$content.= "<div class='subscribe'>";
$content.= "<h4>Enjoyed this article?</h4>";
$content.= "<p>Subscribe to our <a href='http://feeds2.feedburner.com/WpRecipes'>RSS feed</a> and never miss a recipe!</p>";
$content.= "</div>";
}
return $content;
}
add_filter ('the_content', 'insertFootNote');
Credits goes to Cédric Bousmane for that trick!
49 Responses
Nice recipe.
I use this kind of automated content for social bookmarking buttons.
Thanks
Nice recipe. I will consider using this somewhere!
If it’s in your functions.php file, aren’t you going to have to update it when you change your theme?
If you really want it to stick around regardless of what theme you use, you’ll have to create a simple plugin for it, like this:
/*
Plugin Name: Insert text after posts
Description: Automatically insert this text after posts.
*/
function insertFootNote($content) {
if(!is_feed() && !is_home()) {
$content.= “”;
$content.= “Enjoyed this article?”;
$content.= “Subscribe to our RSS feed and never miss a recipe!”;
$content.= “”;
}
return $content;
}
add_filter (‘the_content’, ‘insertFootNote’);
hotness.
Hey, is there any kind of this recipe for blogspot blog?
It’s amazing what could be done with functions.php. Simple hacks like this saves me from installing plugins.
I’m a beginner
What I have to chance to insert something before the content?
Nice recipe! Thanks!
Hello everybody
It’s possible to add this before the content ?
Sorry for my english
@Kakushin: Create a variable and put your desired content. Name it $moreConte, for example.
Then:
if(!is_feed() && !is_home()) {
$content.= $moreContent.$content;
}
return $content;
Not tested, but it should work.
my theme functions.php seemed to show an error after putting the code …as well the whole text came before the header started…did i place the code wrong
I think there is a plugin that already does that.
It is called Add Post Footer and you find it here:
http://www.freetimefoto.com/add_post_footer_plugin_wordpress
Hi, can I replace those words (Subscribe to our blablabla..) with adsense code?
Very cool! Never thought of doing it this way but it makes sense. I probably would have cracked open the php files and hard coded this in but this is much easier.
Thanks!
please let me copy your simple code, and thanks again.
Trackbacks: