Common WordPress End-of-Post Content

I like to have a common element at the end of all my blog posts, but before the comments section. Sometimes this is to highlight upcoming shows, other times it is a special sales discount, a cool tagline, or like here on the lab blog, the Buy me a coffee block.

There are many WordPress plugins that can be used to include such messages, and much more! But just for a simple html block, that’s a bit overkill. Additionally, each plugin requires some custom CSS code and eventually, this slows down page loading.

With just a few lines of code, you can add your own custom post content. Place following code in the functions.php file of your WordPress child theme and replace place…your…html…code…here with your desired content. Please pay attention to continue to encapsulate it with single or double quotes:

function dlp_after_post_content($content){
   if (is_single()) {
      $content .= 'place...your...html...code...here';
   }
   return $content;
}
add_filter( "the_content", "dlp_after_post_content" );

Don’t add this code to the functions.php file of your WordPress theme because it will overwritten the next time a theme is exported from Backlight! You have been warned 😉

If you don’t have a functions.php file yet, create a new file, named it functions.php and place following code in there:

<?php

function dlp_after_post_content($content){
   if (is_single()) {
      $content .= 'place...your...html...code...here';
   }
   return $content;
}
add_filter( "the_content", "dlp_after_post_content" );

?>

It is important that there are no empty characters or lines beyond the enclosing ‘‘ tags!

If you don’t know what a WordPress child theme is and can’t figure it out with the help of the internet, no worries, I’ll write a separate post in the near future.


Did you like this post? Did you use the given code? Please consider supporting me by buying me a coffee!

Buy Me A Coffee


Thanks!

Leave a Reply

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

Web Design Consulting

Do you need help designing your web site or getting Backlight working the way you want? Contact me to discuss your idea or project.


Buy me a Coffee

If you like what I share here, please consider buying me a coffee or a print. This helps keeping me motivated to continue posting. Thank you!

Buy Me A Coffee

Categories