Jump to content

Adsense in first post and after first paragraph


mark007

Recommended Posts

Hi,

I would like to place Adsense in the first post and after first paragraph of the post.

Right now I use this code in post template:

{{if $_REQUEST['ad_inside_first_post'] = !isset($_REQUEST['ad_inside_first_post']) ? 1 : 0}}			
          {advertisement="....."}
{{endif}}

Is there a way to show advertisement after first paragraph in the first post?

Many thanks in advance!

Link to comment
Share on other sites

The solution in Wordpress is like this:

It would be great to have it also for IPS :)

function insert_ad_block( $text ) {
 
if ( is_single() ) :
 
$ads_text = 'ERASE-THIS-PART-AND-PASTE-IN-YOUR-ADSENSE-CODE-HERE';
$split_by = "\n";
$insert_after = 1; //number of paragraphs
 
// make array of paragraphs
$paragraphs = explode( $split_by, $text);
 
// if array elements are less than $insert_after set the insert point at the end
$len = count( $paragraphs );
if ( $len < $insert_after ) $insert_after = $len; // insert $ads_text into the array at the specified point array_splice( $paragraphs, $insert_after, 0, $ads_text ); // loop through array and build string for output foreach( $paragraphs as $paragraph ) { $new_text .= $paragraph; } return $new_text; endif; return $text; } 
 
add_filter('the_content', 'insert_ad_block');

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...