WordPress Tip: Insert Content automatically after each Post in wordpress

WordPress is a great blogging platform which is highly configurable. It allows you a lot of things to do with your Blog. For example, notice the Share Buttons at the end of this post. User can click on those buttons and share this article in any of their favorite social site. If you have subscribe for RSS feed for this blog, you may notice the same buttons at the end of the article in your RSS Reader. So how to add content automatically after each Post? Simple, use WordPress Hooks to add Filters that add content. For example copy below code in functions.php file inside your theme folder.
function insertRSSFootNote($content) { if(!is_feed() && !is_home()) { $content.= "<div class='subscribe'>"; $content.= "<h4>Enjoyed this article?</h4>"; $content.= "<p>Subscribe to our <a href='https://www.viralpatel.net/feed'>RSS feed</a> and never miss a recipe!</p>"; $content.= "</div>"; } return $content; } add_filter ('the_content', 'insertRSSFootNote');
Code language: PHP (php)
The insertRSSFootNote() function in above code simply append any text in the $content variable. Then, our insertRSSFootNote() function is hooked to the the_content() function, and it is automatically called every time the the_content is called. Using this function is basically the same as typing in the text at the end of each post. Notice the (!is_feed) condition on line 2, which prevents the text from being inserted in the RSS feed. If you want the text to appear in your RSS feed, replace line 2 with the following:
if (!is_home()) {
Code language: PHP (php)
Simply modify the code and add text of your choice at the end of each post in WordPress. Happy Blogging…

View Comments

  • Hi, I am using wordpress learning theme, I have added the code but it is not working :(. is there any alternate solution ? I want to add google adds after every post, waiting for good comments, thanks,

  • Hi,

    I want to obtain a set of news from rss feeds and store them in the database.

    I`m using some feeds that do not provide images. So, I would like to know if this plugin allow users to get the images from the google images (or other source) automatically. The key words to search the images would be "Title" of the news.

    I want that all my posts (obtained from the feeds) have images to show in my listing.

    Thank you.

  • Hey there!
    I noticed this post, and found it quite informative. Although the instructions do work, it can be a little risky to add code to your theme, as when it is updated that code will be lost. You could get around this by using a child theme, but I think I have an easier way :-).
    We at 2MB solutions have just released our first (totally free!) plugin, called 2MB Autocode. It allows you to place text at the top or bottom of each post, with an override on a per-post basis. It basically does what this is talking about, except without the theme overwriting it each update :-). You can find it here: http://wordpress.org/plugins/2mb-autocode/ or you can look at our website: http://2mb.solutions.
    Happy blogging!
    -Michael, 2MB Solutions.

Share
Published by
Viral Patel
Tags: wordpress wordpress tips

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

4 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

4 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

4 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

4 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

4 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

5 years ago