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:


<?php
/*
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');
}

?>

91 comments

  1. 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.

  2. 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 :)

  3. 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?

  4. 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!

  5. 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?

  6. 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).

  7. 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.

  8. When I modify the text to what I want, I can’t save the changes. It tells me “You need to make this file writable before you can save your changes.” How do I do that?

  9. Hi,I`m a bit confused here.So,I installed the plugin,activated it,went to plugins editor,then to bottom of every post.text,added the G+ code and updated the file ,but nothing shows.What am I doing wrong?
    Another thing please,can I use it to added hyper links ,like Facebook page like with the content?

  10. Love this plugin for my posts. What about pages? Do you have a code for bottom of every page? thank you!

  11. Great plugin! I’m using a Studio Press Child theme, and am not adept at hooks, so I was losing my mind trying to do what I wanted.

    You saved it!

  12. another thumbs up from me and one question … if there are a few posts I would like it to “display none” on, how do I do that?

  13. Nice plugin … just wanted to know if I can add Jetpack’s contact form code below each post to display contact form. I need to fetch the Author’s email and insert it in the code. Will this allow to execute PHP code ?

  14. Corey – thanks for this plugin!

    Trajan or Corey – I’m trying to have this display only on the single post view, not the home page.

    I turned the content on the .txt page into a div as suggested above. But am not sure where to but the two rules.

    I tried pasting them into the styles.css file (under =layout and .postfooter) but that didn’t do anything.

    I’m not a code monkey so it is probably my error. But I would love for this to work on single posts only if you have any assistance! Thank you.

  15. Is it possible to insert a picture in place of the text with this plugin. I really like the plugin but thought it would be a great spot for a gif of my signature after each post

  16. I have a much easier method of getting the plugin to ONLY display on the single post page… rather than the overly-complicated way posted above using CSS.

    Simply change

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

    to

    if( is_single( ) && file_exists( $fileName )){

    That’s it.

  17. I have your Bottom of Every Post plugin installed. Now instead of adding related posts at the bottom of each post, it has this text with links: “Thanks for installing the Bottom of every post plugin by Corey Salzano. Contact me if you need custom WordPress plugins or website design.” Is there any way to remove this AND how can I get my related posts back to the bottom?

  18. Hey Corey,

    Just wanted to say that I just installed your plugin with great success. It’s working beautifully and solved what I thought was going to be a couple of days of work of coding myself.

    Thanks!

  19. Nick: I would make it a separate plugin to keep this one simple. Right now, paid work is capturing my focus, and I already have a backlog of 2 finished free plugins that I have yet to publish.

  20. Corey, Thanks so much for the plugin, its a fantastic, simple function to do exactly what I needed! I’m clueless about code. What I need is for the custom text to NOT appear on Category Archive pages. I saw your response to Rebecca above, and tried replacing is_home with has_category but that did not make the code not appear on the Category Archive pages. Looked at the codex page also, but don’t see anything different. Any help?

  21. Corey, I’ve discovered by trial ‘n error, mostly error!, the answer to my question above (removing the text added to the bottom of each post on Category Archive pages), at least it works on the theme I’m using, which is to add:
    && !is_archive( )
    to the function code so that the result looks like this:
    if( !is_page( ) && !is_archive( ) && file_exists( $fileName )){

    Again, thanks for the great plugin!

  22. Thanks for your plugin, did the trick for me, without any extra useless feature.
    May be useful one day if I decide to try and create some plugin for my own website.

  23. I used this plugin for a customer today who wanted a dotted line in between posts. It works fine and its compatible with WordPress 3.5.1
    Thnx!

  24. Hey Corey,
    I love your plugin and have added my own Opt-in box to the bottom of each post, However, i keep getting this big gap in-between the end of my post and the plug-in content (like i have several blank lines in there). Do you know how I can get rid of this? It only happens when I activate this plugin.
    You can see it on one of my pages here: http://provennutritionforkids.com/nutritional-healing/

  25. Bonnie: There are two empty paragraph elements before the image. I used FireFox’s Inspector tool to hover over the area and find the empty elements.

  26. After searching through several plug-ins that claimed to allow me to create a post footer, only to find them way too confusing to set up, I finally found one that is super easy to use and actually works: this one! I don’t know how to rate plug-ins on WP (tell me how and I’ll do it) so I at least wanted to post a comment here to say THANK YOU for this easy to use plug-in

  27. Hey Corey,

    I am super excited about this plug-in. Only issue…how do I “activate” the .txt file. The plug-in itself is activated but the .txt file shows “inactive.” thanks!

  28. Sheila: Even though the text file reads “inactive,” it will be used properly. This shouldn’t prevent you from using the plugin.

  29. I love this plug-in! I use it on two of my websites. On the one I’m currently working on, I don’t want the plugin to run on posts with the category slug “succulent-ebook”. I’ve tried for quite a while to modify the text you gave for the home page removal but I can’t get it to work. I keep getting an error:

    This plugin has been deactivated because your changes resulted in a fatal error. Parse error: syntax error, unexpected $end in /home5/cassidyt/public_html/succulentsandsunshine/wp-content/plugins/bottom-of-every-post/bottom_of_every_post.php on line 59

    I’m trying to use the home page fix and a category fix, so I have the category fix right below the home page fix.

  30. I’m trying to remove the message from a custom post type. I followed the example above and changed

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

    to

    if( !is_page( ) && !is_post_type_archive(“Design Approval System”) && file_exists( $fileName )) {

    but nothing happend. Any suggestions?

  31. Hi…I’ve been using “Bottom of Every Post” for a while and really love the functionality it gives me. Calendar events are apparently treated just like any other post for the purposes of display and so “Bottom of Every Post” dutifully puts the same thing on the bottom of my calendar entries as it does on every other post. Do you know any way to disable this behavior? Thanks! Tom

  32. Tom:

    No, I don’t. It likely depends on what calendar plugin you are using and how those posts could be identified in a PHP if statement.

  33. This plugin is AMAZING!

    I tried a few other ones but they were way overcomplicated. This is exactly what I wanted.

    For those of you wanting something that DOES NOT require you to be able to code, check out Magic Action Box.

    As for me, I just wanted to drop some HTML code at the bottom of every post. This was exactly what I was looking for. You’re my hero.

    Thank you.

  34. This plug in is very nice in it’s simplicity. I would however like it to show below the “read more” link at the bottom of all post lead ins. Right now it shows above that link. Any ideas on how to change the order of these two links?

  35. Hi Corey, despite my attempts at following the recommendations above for preventing the plugin from showing on my website’s “portfolio” pages. I tried the has_category instead of is_home recommendation, but no luck.

    I’m unfamiliar with php so I’m guessing I simply left something out. If you could provide me the specific code I need to replace in the plugin php file, I’d be more than glad to pay you for your time. Thanks for the plugin.

    p.s. my website can be found by clicking my profile pic.

  36. Hi Guys! I’ve installed this plugin in wordpress but I cannot find the button to edit this my text on settings panel. Where it is?

    tKS so much for your help lol

  37. Ok, I know I did this before… I took the text off the bottom of the posts listed on the home page. I’ve followed the directions above to modify the .txt file, and I’ve not found the code you mentioned or the one that replaces it.

    I’m sure it’s something I’m missing, but help. :)

  38. Hey, Corey. Loved your plugin! Wonder if you could help me with removing the functionality on the archive page, which in this case is the landing page for our online store at http://www.mamaandbabylove.com/shop/ . I tried the code you offered on your website to do this, but it doesn’t appear to be changing anything. Here’s what I’m using:

    if( !is_page( ) && ‘shop’ != get_post_type() && file_exists( $fileName )){

    Thoughts? Thanks!

  39. Oops, looks like I figured it out. Get the right post type in there, and it works like a charm. Thanks for the plugin!

    -Aimee

  40. Wow you sure did delay accepting that update. There was a notice in the release notes that no one reads, and some angry guy made a support topic about this a year ago. Google cache will have your old content.

  41. Interesting. I just installed it recently and I saw no notification of any update when I installed it…just when I updated WP. But thanks for reminding me of Google cache…great idea!

  42. One more thing. When using your plugin, the text I added at the “bottom of every post” shows even on archive pages where multiple posts are listed. Is there a way to suppress that and only have it show when someone clicks on the full post/page?

  43. I was having a similar problem to many of the posters. I wanted to add a linked image to the bottom of every post. When I did this using the plugin, the image would show up in the blogroll after each abbreviated blog. I was able to solve the problem by changing the line:

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

    to

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

    This makes sure that the added content is only added to a blog page that is displaying a single post. I thought this might help a few other people.

  44. Hi Corey

    This looks good and simple. I want to add a short code to the bottom of a custom post type for all posts. Is this possible with your plugin? I think that a short code will not be executed.

  45. Hi Corey!

    I just installed this plugin and got it set up to show on individual posts instead of the home page (AWESOME!) but I’m wondering if there is a way to change the font size??? Obviously I know nothing about writing code and I’m sure this is an easy fix, but google is not being helpful today!

  46. Hi Corey,

    I love your plugin! I have one question, and I’m not sure if this plugin can do it.

    I would like to have a different message at the end of each post, and have them differ based on category.

    Say for the category “Podcast”, each post would have the same content at the end, and the category “Fitness” would have something different. If you have any ideas of how I could achieve this with this or another plugin, let me know!

    Thanks

  47. This probably isn’t the plugin for your needs. I would write a custom plugin to accomplish that. I wonder if your theme is displaying the category description already? If not, I would append that to posts. If not, you’d just need a place to store the content you want to append to each post for as many categories as your site contains.

  48. Corey, this very clean plugin is refreshing. Thank you for this page to support such a great plugin. I’m fairly new to WP and found this to be very easy to install and implement. Using shortcodes in this plugin makes it even more valuable. Your work is appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>