Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Center area post/pages »

[SOLVED] Add Adsense section targeting code to single.php


  #1  
Old Nov 19, 2010, 06:02 AM
Stefan72
 
8 posts · Oct 2010
Another thread on the forum mentioned adding the code immediately below to the index.php as there is no single.php

<?php if ( is_single() ) { ?>
YOUR CODE HERE
<?php } ?>

The code I need to add is

<!-- google_ad_section_start -->

<!-- google_ad_section_end -->

In the middle of Google's 2 lines of code I also need to have the code that relates to the entire content of each post. I am new to coding and know it should look something like the_content() but not sure exactly.

Can you tell me what code in its entirety I need to add to index.php and where exactly I should put it?

Thanks very much.

Last edited by Stefan72; Nov 19, 2010 at 06:06 AM.
  #2  
Old Nov 19, 2010, 06:17 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
What version of Atahualpa and WP?
You should add it in the option at ato->Style & edit CENTER COLUMN->Content ABOVE the LOOP
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #3  
Old Nov 19, 2010, 06:33 AM
Stefan72
 
8 posts · Oct 2010
Thanks for your reply. I'm using Atahualpa 3.5.3 and WP 3.0.1

Do I add the code below the code that is currently showing in the above the loop box, or is there anywhere else I should be putting it?

Would you mind listing the exact code I should be adding? Would it be,

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
<?php the_content(); ?>
<!-- google_ad_section_end -->
<?php } ?>

Thanks again
  #4  
Old Nov 19, 2010, 07:26 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
HTML Code:
<?php if ( is_single() ) { ?>
<!-- google_ad_code -->
<?php } ?>
using this would only show the ad on a page that was a single post. Is that what you want?
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #5  
Old Nov 19, 2010, 07:38 AM
Stefan72
 
8 posts · Oct 2010
Yes, I just want it in single posts, but I've already got the actual ad code embedded in specific posts, by copying it to the html view of the edit post screen in wordpress.

I'm told I just need this extra bit of coding, in theory to the single.php file, that tells google to focus adsense ads on the content of each post only, rather than all the text visible on any given page e.g. the site title, sidebars and so on.

Google's advice - see https://www.google.com/adsense/suppo...n&answer=23168 - suggests using the 2 bits of code like this, but where it says "This is the text of your webpage. Most of your content resides here," I'm not sure what you'd replace it with for Atahualpa.

<html><head><title>Section targeting</title></head>
<body>
<!-- google_ad_section_start -->

This is the text of your webpage. Most of your content resides here.

<!-- google_ad_section_end -->
</body>
</html>

Last edited by Stefan72; Nov 19, 2010 at 11:51 AM.
  #6  
Old Nov 19, 2010, 11:58 AM
Stefan72
 
8 posts · Oct 2010
Hi again,

Should I be putting this code as the last bit of code in the above the loop box?

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
<?php the_content(); ?>
<!-- google_ad_section_end -->
<?php } ?>

Is the <?php the_content(); ?> bit in the middle correct?

Thanks
  #7  
Old Nov 19, 2010, 01:13 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
You should probably put the start in the above the loop section, and the end in the below the loop section
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #8  
Old Nov 19, 2010, 02:45 PM
Stefan72
 
8 posts · Oct 2010
Sorry, just to be clear,

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
<?php the_content(); ?>

in the above the loop, and

<!-- google_ad_section_end -->
<?php } ?>

in the below the loop, or something else?

Thanks
  #9  
Old Nov 19, 2010, 03:32 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
I don't think you want the line the_content() at all, the loop will be providing the content. You should also check for the is_single() for the closing ad code. Don't forget that you will have to wrap the bottom part in the <?php
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #10  
Old Nov 19, 2010, 03:49 PM
Stefan72
 
8 posts · Oct 2010
Hi again,

Hopefully almost there. I put,

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->

in above the loop box at the end of the rest of the code, and

<!-- google_ad_section_end -->
<?php } ?>

in below the loop box again at the end of the rest of the code but got this error,

Parse error: syntax error, unexpected $end in /home/stefan01/public_html/wp-content/themes/atahualpa353/functions.php(532) : eval()'d code on line 8

Do you know what I did wrong. Sorry if I misunderstood your last reply but very new to this stuff. If there's any chance you could spell out to me exactly what code I need to put where, I'd be very grateful.

Thanks...
  #11  
Old Nov 20, 2010, 05:07 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
HTML Code:
<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
?>
same for the end
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #12  
Old Nov 20, 2010, 12:47 PM
Stefan72
 
8 posts · Oct 2010
Hi,

Added the code as follows,

above the loop right at the end of the rest of the code:

<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
?>

below the loop right at the end of the rest of the code:

<?php if ( is_single() ) { ?>
<!-- google_ad_section_end -->
?>

but got this error...

Parse error: syntax error, unexpected $end in /home/stefan01/public_html/wp-content/themes/atahualpa353/functions.php(532) : eval()'d code on line 9

Do you know if there's anything else I could try. Thanks very much.
  #13  
Old Nov 20, 2010, 01:16 PM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
you can't have an open '{' with out a close '}' - it seems like you need to learn some php and HTML so you know how to add things like this. you have
HTML Code:
<?php if ( is_single() ) { ?>
<!-- google_ad_section_start -->
?>
The '<?php' switches you into php syntax, then you have the
HTML Code:
if ( is_single() )
that is the if statement and if conditional.

Next comes true section. If you have more than one statement, they need to be in {...}, with just one true statement you can ignore the {}. But since you have the opening '{' that is what starts the true statement. In order to use HTML in thresult, upi have to switch oout of PH and so you have teh '?>' to do it. This is followed by the html google statement
HTML Code:
<!-- google_ad_section_start -->
followed by a '?>' - this is invalid since you are trying to switch back to HTML mode, but you are in it...and you need the closing '}' so you must code
HTML Code:
<?php }; ?>
I would suggest taking some time to learn some basic HTML, CSS and PHP if you are going to be adding anything more to your site

Good luck
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #14  
Old Nov 24, 2010, 05:58 AM
Stefan72
 
8 posts · Oct 2010
Thanks, it looks like that has worked.

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to put code in loop with instruction for single.php? annsworld Center area post/pages 5 Dec 1, 2012 09:52 PM
How to add PHP to the loop on multi- and single post pages only? Fux Center area post/pages 2 Jun 16, 2010 04:55 AM
Add code after post text but before the tags section Wonderbaum Post-Kicker, -Byline & -Footer 2 May 22, 2010 06:02 PM
How to add php code to a 'single' page JakeThePeg Center area post/pages 8 Mar 21, 2010 01:21 AM
Executing PHP Code in "HTML Inserts Header" Section twola Forum How-To 1 Sep 30, 2009 04:51 AM


All times are GMT -6. The time now is 04:55 PM.


Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.