Add content to the bottom of every WordPress 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: https://coreysalzano.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

107 responses to “Add content to the bottom of every WordPress post”

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

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

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

  4. This is an awesome WP plugin. Easy to use, and install. Cool. Thanks a bunch!

  5. Glad I could help!

  6. This is a great plugin. The simplicity is great. however I would really like to disable it on the excerpt.

  7. Does what is says simple and useful.

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

  9. How do I change the color of the footer font?

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

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

  12. Trajan McGill

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

  13. Trajan McGill

    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.

  14. Fantastic plugin, please tell me where I can change the font colour or where pluginis is to be found in editor, thanks

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

  16. Karel: If the server is Linux based, you can use the command CHMOD to change the file permissions.

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

  18. This is fantastic! I’ve been looking for this simple solution for a week now!! Thank you.

  19. sally

    bottom_of_every_post.txt (inactive)??

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

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

  22. Fantastic and simple plugin! Thank you!

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

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

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

  26. Tyler: There are instructions to prevent the message from showing your home page at the top of this page.

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

  28. Joanne: Sure, you could put HTML code to display an image in the text file. Any content could be used, really.

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

  30. I installed and edited the txt file but the txt file shows as inactive (even though the plug-in is activated).

    How can I get the text file activated?

  31. Michelle: The text file will always display as inactive because it’s not a script.

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

  33. Amy: Sounds like you didn’t read the installation instructions: http://wordpress.org/extend/plugins/bottom-of-every-post/installation/

  34. Installed plugin (awesome, btw) on multisite. Shut it off for select blogs?

  35. LOVE this plug-in!

    Is there a way to only have it appear on specific categories of posts? Or to exclude it from specific categories?

  36. Rebecca: Sure. You will have to read the post above about excluding it from the home page, and modify that code to use has_category instead of is_home. http://codex.wordpress.org/Function_Reference/has_category

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

  38. Glad I could help.

  39. This would be perfect if I could specify only certain categories. Any chance of that? I know this is pretty much a ‘featureless’ plugin.

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

  41. I was able to modify the plugin to do as I needed. Thanks!

  42. Awesome. If you have made a plugin that could be useful to others, consider sharing your code.

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

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

  45. I love your plugin and tell people about it every chance I get. I use it to run a mailing list signup form at the bottom of every post. Thanks!

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

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

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

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

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

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

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

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

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

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

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

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

  58. Was looking for exactly this one for my website.. Thanks Mate!!

  59. Exactly what I was looking for, it works great. Thanks!

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

  61. Jay:

    I think the only way to do that is by editing the theme’s template to embed the message.

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

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

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

  65. The code changes happen in the php file.

  66. Found it! It turns out I didn’t search for the Blog code in the php section. I knew it was something small. Thank you so much!

  67. Yeah.. that didn’t work. Maybe it’s something with my theme. *sigh*

  68. Is it possible to run a using this plugin?

  69. Cody, I think you accidentally a whole word.

  70. Oops. Haha. I meant to say, script. Is it possible to to run a script using this plugin?

  71. If you mean JavaScript, then yes, you can put some JS in the text file and it will execute once for every post on the page.

  72. Awesome! Thanks Corey for your lightning quick help and for this plugin. It is exactly what I was looking for.

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

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

  75. Disappointed that updating this plugin stripped out all the text I had in the previous version. Lesson learned! :(

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

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

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

  79. Stevie Knight

    Never mind. I found the instructions. This makes this plugin a MUST have! Thanks.

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

  81. Awesome plug in! Can I buy you a up of coffee?

  82. Sure, I’m glad you like it.

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

  84. Johan: Read this to find out how to add short code support: http://wordpress.org/support/topic/shortcode-not-working-42

  85. Thanks Corey ;-)

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

  87. Laura: Your font sizes are controlled by your theme’s CSS, not any plugin code.

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

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

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

  91. Thanks so much for the plugin. It is exactly what I needed. Can you tell me how to exclude posts published before a certain date? I need to add the text to post published after 12/22/2014.

    Thanks!!

  92. So I was able to remove the text from previous posts so I don’t need to do it though the php file. But what I DO need is to remove the text from excerpts.

  93. Ankurman Shrestha

    Thank you Corey! Great work!!!

  94. Thanks, Corey, this is just the thing I was looking for. I love things that have just the feature you’re looking for and no more!

  95. My site has the Bottom of Every Post content showing up on each of the different Page Sections (using a Parallex theme) on my homepage in mobile, even after I deleted the Bottom of Every Post plugin. Please help.

  96. Sounds like you’re looking at a cached version of the page, Michael.

  97. Corey,
    It appears your right. When I use a mobile emulator (http://quirktools.com/screenfly/) the left over content doesn’t show up. I cleared my cache on my phone and used Firefox and Chrome to test but it still shows up. Any idea why?

  98. Corey,
    I’ve tried multiple browsers on multiple computers. The left over content from the Bottom of Every Post plugin is still there on my homepage repeated over and over, even though I deleted the plugin and erased what was in the txt file for the plugin. Any ideas?

  99. If my plugin isn’t even installed anymore, my plugin isn’t the problem. I don’t know what your issue may be.

  100. How do I easily remove the desired text in post excerpts? This plugin is saving my butt with the exception that I really don’t want it show in the excerpts.

    See here: http://www.theyearofmud.com/blog/

    Thanks a lot!

  101. You have to explicitly create excerpts. The excerpts that are automatically generated by WordPress for your posts still apply the_content filters to the output, so there is no way to target full posts and not automatically generated excerpts.

    https://wordpress.org/support/topic/stop-it-from-showing-after-the-more-link/

  102. Alf space

    The plugin does not work with wordpess 4.9.1, when I install it, the EDIT option does not appear in the plugin, I used it a lot a month ago but it does not work anymore, will it have an update? Thank you

  103. Can you still reach the editor via the Plugins menu?

  104. Is there a way to add it only to the bottom of posts in a specific category?? I want to add a Mycred Send gift button to the bottom of of posts in one of my websites categories.

  105. Yes, read this page.

  106. Sohail Ahmad

    Finally found it. Thank you so much.