WP: Add content to the bottom of every post

Bottom of every post is a WordPress plugin I wrote in 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.

This plugin will never be updated, and that is a good thing. It is very simple and designed for you to make edits to suit your needs. An update would erase your customizations, so there will never be a new version.

How can I 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.
How can I remove the message from my home page posts?
You’ll have to edit the plugin. Find this line:

if( !is_page( ) && file_exists( $fileName )){

…and change that code to one of these lines depending on your configuration:

Blog post home page

if( !is_page( ) && !is_home( ) && file_exists( $fileName )){

Static front page

if( !is_page( ) && !is_front_page( ) && file_exists( $fileName )){

How can I not show the message on a certain category?
First, be sure whether you need a category exclusion or a custom post type exclusion. For categories, add a call to has_category:

Exclude a category

if( !is_page( ) && !has_category('portfolio') && file_exists( $fileName )){

Exclude a custom post type

if( !is_page( ) && 'portfolio' != get_post_type() && file_exists( $fileName )){

Download bottom-of-every-post.zip

Installation instructions

  1. Modify `bottom-of-every-post.txt` to contain the content you would like at the bottom of every post
  2. Upload the `bottom-of-every-post` folder to the `/wp-content/plugins/` directory
  3. 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:

Plugin Name: Bottom of every post
Plugin URI: http://www.umbrellastudio.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');