How to Insert Any Content to the Bottom of Every Post in WordPress

  • Post last modified:Last updated on August 12, 2022
  • Post author:By

Inserting content to your posts programmatically can be a time saver. You might need to add a notification message, a disclosure message or maybe you need to add a shortcode.

In this guide, we will show you how to add content to the bottom of your posts using a WordPress filter and a little bit of code.

Let’s get started!

How to Insert Any Content to the Bottom of Every Post in WordPress

WordPress Filters

WordPress filters are functions that allow you to manipulate and change the value of a defined variable. There are multiple filters available in WordPress and they can be found in the official documentation.

We will be using a filter called the_content. This function filters the content of a post or page after it is queried from the database and before it is printed to the screen, which makes it the perfect candidate to filter the content of the posts and add our extra content.

Adding Custom Code

Before making any changes, we recommend you make a full backup of your site. This will help you restore and recover your website if anything breaks while editing your theme files.

Next, let’s edit the functions.php file of your active theme. To do this, you’ll need to copy this code and paste it at the end of the file:

/**
 * @snippet       WordPress insert content after the post's body
 * @author        https://getstartedwp.com/
 */
function gswp_insert_content_after_post_body( $content ) {
	if ( is_single() ) {
		$content .= '<p>This is inserted after the post body.</p>';
	}
	return $content;
}

add_filter( 'the_content', 'gswp_insert_content_after_post_body' );

This code adds “This is inserted after the post body text” after any post on your website. Now go ahead and replace line #7 with the content you need.

If you want to add a shortcode instead of plain text, you could update line #7 with:

$content .= do_shortcode( '[your_shortcode_here]' );

We hope this article helped you to learn how to insert any content to the bottom of every post in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Editorial Team

The GetStartedWP editorial team is a team of WordPress experts and developers. We are passionate about creating and sharing content like tutorials and guides about the entire WordPress ecosystem.

Disclousure: Our content is reader-supported. This means if you click on some of our links, then we may earn a small commission.

Leave a Reply