redwaves lite - manul adsense code insertion
Topics related to RedWaves lite theme goes here.


New Member Rank
Posts: 1
Joined: Mon Jan 08, 2018 7:29 am
Display Name: ahmed

redwaves lite - manul adsense code insertion

linkPost by ahmed » Mon Jan 08, 2018 7:33 am

hello dear redwaves lite admin
i need to insert adsense manually ( without any plugin ) code exactly before the title and in the middle , and of each single post using php , how i can do that ? thanks
User avatar
Asmi Khalil

Site Admin Rank
Posts: 781
Joined: Fri Jun 26, 2015 7:13 am
Display Name: Asmi Khalil
Location: Tunisia

Re: redwaves lite - manul adsense code insertion

linkPost by admin » Fri Feb 09, 2018 11:49 pm

Hi Ahmed,
Thanks for using RedWaves lite!

To display your Adsense add before post title, open /template-parts/content-single.php and add your Adsense code right before <header class="entry-header"> (line 9).

To display your ad in the middle of content, edit the same file and add this code;
<?php add_filter( 'the_content', 'redwaves_lite_post_ad' ); // Show an ad within post content! ?>
Right before this line;
<?php the_content(); ?>
Then add this function at the end of your functions.php file;
function redwaves_lite_post_ad( $content ) {

	$content_block = explode( '<p>', $content );
	$size = count( $content_block );
	$position = (int) ( $size / 2 );

	if ( !empty( $content_block[$position] ) ) {
		$content_block[$position] .= 

	for ( $i=1; $i < count( $content_block ); $i++ ) {
		$content_block[$i] = '<p>'. $content_block[$i];

	$content = implode( '', $content_block );

	return $content;
Replace PUT YOUR ADSENSE CODE HERE with your Adsense JS code.
I think there is a world market for maybe five computers. - IBM chairman Thomas Watson, 1943

Who is online

Users browsing this forum: No registered users and 2 guests

It is currently Wed Oct 16, 2019 3:08 am