Add/Insert Custom Text In WordPress Posts

Lets say you want to insert custom text or HTML snippet in your WordPress post content, and you may be thinking different approaches like manually editing hundreds of post and inserting them? Well! that's just time consuming! Try these PHP codes for WordPress that will easily insert your text or HTML in your posts.
  1. Edit functions.php by going to Appearance -> editor in your WordPress admin section.
    OR
    Open functions.php using ftp or file manager, which can be found inside your-site.com/wp-content/themes/your-theme/
  2. Copy required PHP snippet from boxes below and paste it within functions.php and save it.

Insert Custom Text Below Content

To make text appear below the WordPress post content, copy and paste code below in your functions.php and save it. [cc lang="php"] add_filter('the_content', 'add_my_content'); function add_my_content($content) { $my_custom_text = 'This is my text'; // text-html to replace if(is_single() && !is_home()) { $content .= $my_custom_text; } return $content; }[/cc]

Insert Custom Text Above Content

To make text appear above the WordPress post content, copy and paste code below in your functions.php and save it. [cc lang="php"] add_filter('the_content', 'add_my_content'); function add_my_content($content) { $my_custom_text = 'This is my text'; // text-html to replace if(is_single() && !is_home()) { $content = $my_custom_text.$content; } return $content; } [/cc]

Insert Custom Text Above and Below Content

To make text appear above and below WordPress the post content, copy and paste code below in your functions.php and save it. [cc lang="php"] add_filter('the_content', 'add_my_content'); function add_my_content($content) { $my_custom_text = 'This is my text'; //text-html to replace if(is_single() && !is_home()) { $content = $my_custom_text.$content.$my_custom_text; } return $content; } [/cc]

Insert Custom Text After each Paragraph

To make text appear text after each paragraph in post content, copy and paste code below in your functions.php and save it. [cc lang="php"] add_filter('the_content', 'txt_after_every_para'); function txt_after_every_para($content) {$my_custom_text = '

Text Test

'; // text-html to replaceif(is_single() && !is_home()) { $my_content = explode("

", $content); for ($i = 0; $i After Each Specified Paragraph Number We can also make text appear text after each paragraph number we specify in post content, copy and paste code below in your functions.php and save it. Change $my_custom_text and $after_paragraphs paragraph numbers in array. [cc lang="php"] add_filter('the_content', 'txt_after_every_para'); function txt_after_every_para($content) { $my_custom_text = '

Text Test

'; // text-html to replace $after_paragraphs = array(1,3,4); //Text appears after paragraph numbers specified here if(is_single() && !is_home()) { $my_content = explode("

", $content); for ($i = 0; $i
  • Hey Saran,This is an awesome post! Any chance that it's possible to add custom text above each post on a post by post basis?I'd like to include links (breadcrumb style) above each post, but depending on the post the links will be different so it would be great to be able to edit this text for each post.Thanks! Jon
New question is currently disabled!