How to add adsense banner above post for WordPress theme

Hi Aigars and Movin,

I am wondering where I would place my adsense code if I wanted to have ad directly above post?

Regards,

WP: 4.2.2
Dazzling: current
Site: curlyafrodotcom

Hi Movin,

Just be to be clear; wishing to add ad above the post but below title of posts.

Thanks in advance,

Hi Movin,

In reading the above, I realise there could still be confusion. Is it possible for you to provide code for both options:

  1. placing adsense code DIRECTLY below the title of posts (yet above the line that has date, leave a comment, categories)
  2. placing adsense code DIRECTLY above the posts (i.e. below the line separating content and date, leave a comment, categories)

Apologies if confusing.

Regards,

Hi Movin,

Just wondering if any suggestions to the above query?

Regards,

Hi @4alex,

I hope you are well today and thank you for your questions.

1) placing adsense code DIRECTLY below the title of posts (yet above the line that has date, leave a comment, categories)
  1. placing adsense code DIRECTLY above the posts (i.e. below the line separating content and date, leave a comment, categories)

You can achieve this by overwriting the content-single.php file from the Dazzling theme in to the root directory of your child theme and add the adsense code in this file in the appropriate position as displayed below.

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<header class="entry-header page-header">

		<?php the_post_thumbnail( 'dazzling-featured', array( 'class' => 'thumbnail' )); ?>

		<h1 class="entry-title "><?php the_title(); ?></h1>
			Place the adsense code here to appear it DIRECTLY below the title of posts (yet above the line that has date, leave a comment, categories)
		<div class="entry-meta">
			<?php dazzling_posted_on(); ?>
		</div><!-- .entry-meta -->
	</header><!-- .entry-header -->
		Place the adsense code here to appear it DIRECTLY above the posts (i.e. below the line separating content and date, leave a comment, categories)
	<div class="entry-content">
....

I have attached the sample child theme containing the content-single.php file which you can use to achieve it.

Best Regards,
Movin

Thank you Movin,

I will wrap my head around this in due time.

Regards,

You are most welcome here :slight_smile:

Hi Movin,

Trust you are well?

I finally installed child theme (currently inactivated; I have the parent dazzling theme up). I used the child theme download in the sticky thread of this forum (the first/ top thread). I tried using the attached download you provided, but for some reason when I installed (and activated the theme, and made changes directly to dashboard, ads were duplicated. I eventually had to remove it and install the “sticky post” child theme (however, this one is without the content-single.php file). Given these issues, must I access ftp/content-single.php file on my server to add adsense?

Also, though I removed the child theme with content-single.php file, some posts are still showing the adsense under the title (but with page header removed). How can I best have new child theme (sticky post) implemented with desired ads under the title (yet above author name, date, page header) with now ad duplicates?

My apologies, but need to really sort these changes out as soon as humanly possible.

Regards,

Sorry Moving site details are:

WP: Current
Dazzling : Current
Site: curlyafrodotcom

Regards,

Hi Movin,

I do apologise for bothering you yet again, but I would really like some assistance with effectively implementing/working via a child theme. As indicated above, I am currently working via the parent theme (I previously uploaded the zipped child theme you attached but removed because of issues with the display of the adsense ads - they were showing duplicate ads, one directly above the post and one directly below the title of the posts.) Should I re-upload the zipped files or is it possible to add adsense to parent without using child theme?

Your assistance is much appreciated.

As indicated above, I am currently working via the parent theme (I previously uploaded the zipped child theme you attached but removed because of issues with the display of the adsense ads – they were showing duplicate ads, one directly above the post and one directly below the title of the posts.)

Could you please tell me what changes have you made in the parent theme to display the adsense ads so that i can help you to implement it in the child theme.

Should I re-upload the zipped files or is it possible to add adsense to parent without using child theme?

You can make the changes in the parent theme but if you make changes in the parent theme file then you have to make these changes again after theme updation as changes made in the parent theme files get lost on theme updation.

Hi Movin,

Thanks for your response.

The only change that I have made to Parent theme (i.e. header.php file) is the addition of the top bar (where tag line and social icons are). Any other changes were made in theme (dazzling) options, i.e. css, layout, etc. All of these features are maintained after theme updates.

For the Parent theme, barring the adsense on my top left sidebar that has been there before, I haven’t added any (adsense) code to the theme (i.e. content-single.php file). Previously, I added the above code (in the above specified location of the content-single.php file of child theme you forwarded to me), but given duplicates, I removed the child theme and went back to parent.

Any assistance would be greatly appreciated.

Thanks in advance,

WP: current
Dazzling: current
Site: curlyafrodotcom

Previously, I added the above code (in the above specified location of the content-single.php file of child theme you forwarded to me), but given duplicates, I removed the child theme and went back to parent.

Could you please add that code again that displays you duplicates and share me the child theme with those changes so that i can troubleshoot it on my test site?

Hi Movin,

Thanks for your response.

I used the code you provided in the above reply #25681. (Do you want me to re-install child theme and place code in specified location as below?) I placed the code in the spot for adsense directly below title (tried placing it here but wouldn’t let me). The code is follows:

<article id=“post-<?php the_ID(); ?>” <?php post_class(); ?>>
<header class=“entry-header page-header”>

	&lt;?php the_post_thumbnail( 'dazzling-featured', array( 'class' =&gt; 'thumbnail' )); ?&gt;

	&lt;h1 class="entry-title "&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt;
		PLACE THE ADSENSE CODE HERE TO APPEAR IT DIRECTLY BELOW THE TITLE OF POSTS (yet above the line that has date, leave a comment, categories)
	&lt;div class="entry-meta"&gt;
		&lt;?php dazzling_posted_on(); ?&gt;
	&lt;/div&gt;&lt;!-- .entry-meta --&gt;
&lt;/header&gt;&lt;!-- .entry-header --&gt;
	Place the adsense code here to appear it DIRECTLY above the posts (i.e. below the line separating content and date, leave a comment, categories)
&lt;div class="entry-content"&gt;

Hi Movin,

I re-installed your attached child theme and placed the code in area directly below posts. It seems to be ok now; I realised it may have been the extra code for the adsense above the posts (I removed it, and seems to be ok - fingers crossed). I will keep an eye on it to make sure everything remains as should.

Thanks for all your help.

Glad it’s working fine for you now :slight_smile:

Please advise if you have more questions.

Have a fantastic day!