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.- 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/ - 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; $iText 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- What if I want to add a symbol directly after the last text character in a post?Reply
- 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! JonReply
New question is currently disabled!