Adding content to your posts programmatically can be a real time saver. Maybe you need a disclosure notice under every article, a signup call-to-action, or a shortcode that should appear site-wide. Doing it by hand in dozens of posts is tedious — a few lines of code does it instantly and keeps working for every post you publish in the future.
In this guide, you’ll learn how to append content to every post using the the_content filter and a small code snippet.
How WordPress filters work
WordPress filters are hooks that let you modify a piece of data as WordPress processes it. Dozens of filters exist for different purposes — you’ll find them throughout the official developer documentation.
We’ll use the_content, the filter WordPress applies to a post’s body text after fetching it from the database and before printing it to the screen. It’s the perfect interception point for adding extra content to your posts.
Where to put the code
Don’t edit your parent theme’s functions.php directly — your changes will be wiped out the next time the theme updates. Instead, use one of these:
- Your child theme’s
functions.php(safe from updates), or - A tiny custom plugin — our basic plugin development tutorial shows you exactly how to make one.
And as always: back up your site before touching code. A free backup plugin like UpdraftPlus takes minutes to set up.
Adding the code
Paste this at the end of your child theme’s functions.php (or your custom plugin file):
/**
* Insert content after the post body.
*/
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' );

How it works:
- The function receives the post content, appends your HTML to it, and returns the result.
is_single()ensures it only runs on individual post pages — not your homepage, archives, or pages.add_filter()attaches the function to thethe_contentfilter.
Replace the <p>...</p> line with whatever you need — a disclosure, a newsletter signup, an author bio. To insert a shortcode instead of plain HTML, use:
$content .= do_shortcode( '[your_shortcode_here]' );
Test it
Open any single post on your site — your new content should appear right after the article body. If your site uses caching, clear the cache first or you may not see the change immediately.
That’s it — one snippet, and every current and future post gets your content automatically.
Adding content to your posts programmatically can be a real time saver. Maybe you need a disclosure notice under every article, a signup call-to-action, or a shortcode that should appear site-wide. Doing it by hand in dozens of posts is tedious — a few lines of code does it instantly and keeps working for every post you publish in the future.
Adding content to your posts programmatically can be a real time saver. Maybe you need a disclosure notice under every article, a signup call-to-action, or a shortcode that should appear site-wide. Doing it by hand in dozens of posts is tedious — a few lines of code does it instantly and keeps working for every post you publish in the future.
In this guide, you’ll learn how to append content to every post using the the_content filter and a small code snippet.
In this guide, you’ll learn how to append content to every post using the the_content filter and a small code snippet.
How WordPress filters work
WordPress filters are hooks that let you modify a piece of data as WordPress processes it. Dozens of filters exist for different purposes — you’ll find them throughout the official developer documentation.
WordPress filters are hooks that let you modify a piece of data as WordPress processes it. Dozens of filters exist for different purposes — you’ll find them throughout the official developer documentation.
We’ll use the_content, the filter WordPress applies to a post’s body text after fetching it from the database and before printing it to the screen. It’s the perfect interception point for adding extra content to your posts.
We’ll use the_content, the filter WordPress applies to a post’s body text after fetching it from the database and before printing it to the screen. It’s the perfect interception point for adding extra content to your posts.
Where to put the code
Don’t edit your parent theme’s functions.php directly — your changes will be wiped out the next time the theme updates. Instead, use one of these:
Don’t edit your parent theme’s functions.php directly — your changes will be wiped out the next time the theme updates. Instead, use one of these:
- Your child theme’s
functions.php(safe from updates), or - Your child theme’s
functions.php(safe from updates), or - A tiny custom plugin — our basic plugin development tutorial shows you exactly how to make one.
- A tiny custom plugin — our basic plugin development tutorial shows you exactly how to make one.
And as always: back up your site before touching code. A free backup plugin like UpdraftPlus takes minutes to set up.
And as always: back up your site before touching code. A free backup plugin like UpdraftPlus takes minutes to set up.
Adding the code
Paste this at the end of your child theme’s functions.php (or your custom plugin file):
/** * Insert content after the post body. */ 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' ); 

How it works:
- The function receives the post content, appends your HTML to it, and returns the result.
is_single()ensures it only runs on individual post pages — not your homepage, archives, or pages.is_single()ensures it only runs on individual post pages — not your homepage, archives, or pages.add_filter()attaches the function to thethe_contentfilter.
Replace the <p>...</p> line with whatever you need — a disclosure, a newsletter signup, an author bio. To insert a shortcode instead of plain HTML, use:
Replace the <p>...</p> line with whatever you need — a disclosure, a newsletter signup, an author bio. To insert a shortcode instead of plain HTML, use:
$content .= do_shortcode( '[your_shortcode_here]' ); Test it
Open any single post on your site — your new content should appear right after the article body. If your site uses caching, clear the cache first or you may not see the change immediately.
Open any single post on your site — your new content should appear right after the article body. If your site uses caching, clear the cache first or you may not see the change immediately.
That’s it — one snippet, and every current and future post gets your content automatically.