Back WordPress

How to Insert Code after More Tag within WordPress Post Page

WRITTEN BY ON 02 Mar 2011
11,314 VIEWS • SHARES
0 comments

This Simple tutorial will show you how to add/insert code or advertisement etc. right after the tag, but within the post page. For doing this, all we need is to add some piece of code in your theme’s Functions.php

PHP

This code will replace the with your ad added above in my_ad() Function

add_filter('the_content', 'adds_block');

function adds_block($content){
 if (is_single())
 global $post;
$thePostID = $post->ID; // getting the post ID
$new_insert = '<span id="more-' .$thePostID.'"></span>' ;
 return str_replace($new_insert, my_ad(), $content);
 }
function my_ad(){
 return ' Your Ad Code '; // What you want to display in place of the more tag. can be a custom code, advertisement etc.
}

Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.