WP: Add content to the bottom of every post
I wrote a new WordPress plugin last week, July of 2011. This plugin is a simple filter that adds some content to the bottom of each post. I thought for sure a plugin like this would already exist, and I was surprised to find a few very complex solutions with way more features than necessary.
This plugin has no other features and adds no administration options pages in your admin dashboard (because you can edit the settings via the Plugin editor). The message that is appended to each post is saved in a text file in the plugin directory. I chose a file on disk instead of a WordPress database option because I dislike plugin options pages for simple plugins.
How to edit the message
To edit the message that will be added to the bottom or footer of your posts, Go to Plugins > Editor and choose “Bottom of every post” with the top right selector. The plugin’s files will be loaded on the right. Choose the file `bottom_of_every_post.txt` and edit at will.
Download bottom-of-every-post.zip
Installation instructions
- Modify `bottom-of-every-post.txt` to contain the content you would like at the bottom of every post
- Upload the `bottom-of-every-post` folder to the `/wp-content/plugins/` directory
- Activate the plugin through the ‘Plugins’ menu in WordPress
I am also going to use this code to teach a few people how to create their own WP plugins. Here is the full source code of my new plugin:
<?php
/*
Plugin Name: Bottom of every post
Plugin URI: http://www.tacticaltechnique.com/wordpress/bottom-of-every-post/
Description: Add some content to the bottom of each post.
Version: 1.0
Author: Corey Salzano
Author URI: http://profiles.wordpress.org/users/salzano/
License: GPL2
*/
/*
avoid a name collision, make sure this function is not
already defined */
if( !function_exists("bottom_of_every_post")){
function bottom_of_every_post($content){
/* there is a text file in the same directory as this script */
$fileName = dirname(__FILE__) ."/bottom_of_every_post.txt";
/* we want to change `the_content` of posts, not pages
and the text file must exist for this to work */
if( !is_page( ) && file_exists( $fileName )){
/* open the text file and read its contents */
$theFile = fopen( $fileName, "r");
$msg = fread( $theFile, filesize( $fileName ));
fclose( $theFile );
/* append the text file contents to the end of `the_content` */
return $content . stripslashes( $msg );
} else{
/* if `the_content` belongs to a page or our file is missing
the result of this filter is no change to `the_content` */
return $content;
}
}
/* add our filter function to the hook */
add_filter('the_content', 'bottom_of_every_post');
}
?>
Comments(13)

Interesting idea! I’d probably use it if I could change the text from the WP admin panel. I’d probably the promotional text every day. Thanks.
Bryan:
You CAN change the text from the WP admin panel. Under plugins, click Editor. Choose “Bottom of every post” in the upper right hand corner. Choose the file bottom_of_every_post.txt, and make any changes you like.
I am using your ‘bottom-of-every-post’ plugin to add a google+ button to my blog articles at fraggit.info/fitblog. Works great, I thanks you much :)
This is an awesome WP plugin. Easy to use, and install. Cool. Thanks a bunch!
Glad I could help!
This is a great plugin. The simplicity is great. however I would really like to disable it on the excerpt.
Does what is says simple and useful.
The plugin is great but I have an issue with it: it will append the text on the frontpage even when there is a MORE link in the post, so that the visitor must click it to read the whole post. In this case I don’t wanna the visitor to see the bottom of the post on each and every post, but only below those who showing their full content. Any trick to circumvent this problem?
How do I change the color of the footer font?
I was so excited about this plugin because I wanted to put a Call To Action on the bottom of every post. However, I was so disappointed to learn that I am expected to know how to put the code in myself. I appreciate the thought but for the most part, code is like a foreign language to me.
I would much rather have a options via the admin dashboard where I just type and hyperlink to my hearts desire. After all, those why us code illiterates love wordpress!
Corey, thanks so much for this plugin. Is there a simple way to augment the code so that the bottom-of-post content only loads within the posts themselves and not on the site homepage?
A few people have asked about showing this text only on a single post view and not on the main page. Here’s how I accomplished that.
First, put your bottom-of-post content inside a div with a named class, for instance:
Your bottom content goes here
Then in your stylesheet, set up two rules:
div.EveryPostFooter
{ display: none; }
body.single-post div.EveryPostFooter
{ display: block; }
Now although the bottom text is still added to every post, it won’t be displayed at all except when in single-post view. (How it works: the first rule says not to display any div with class EveryPostFooter. The second rule reverses the first rule, but only in cases where the div is somewhere inside of a body element that has class single-post applied to it, which it does when you’re in single-post view.)
You could modify this technique to do the opposite, if you want (show the text on the main page, but not on the single-post view).
Whoops, my last post failed to show what I wanted, because the comment system stripped out the HTML tags. Rewording the first step above, what I meant was:
First, put your bottom-of-post content inside a div with a named class, for instance:
!div class=”EveryPostFooter”!
Your bottom content goes here
!/div!
Just substitute less-than/greater-than characters (angle brackets) for the exclamation points, to turn them into div tags.