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 »

Adding AdSense to content


  #1  
Old Feb 18, 2009, 01:15 AM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Adding AdSense to content

I would like to add AdSense top and bottom in with the content, and want to have single full posts show up from clicking on a list of links to them in the side bar.
I'm sure it's doable just wondering the easiest way to accomplish it.
I tried one of the AdSense plugins but the bottom of the ad block interfered with my post text.
I tried the add html, javascript box but didn't seem to work.
Thanks for your help I do appreciate it!
Jerry
  #2  
Old Feb 18, 2009, 09:43 AM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Hi again Flynn,
After reading more here http://forum.bytesforall.com/showthread.php?t=366 I thought I would quickly tell you I did donate (not much I'm unemployed like a lot of us in the USA) but I will donate for most every question I have in the future.
Maybe you should have a minimum donation required for you expertise?
  #3  
Old Feb 18, 2009, 02:12 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
Jerry, I did not plan to ignore you. Your's requires a tad more thought and I only answered the quick easy questions the last 2 days. Thank you for the donation.

Where exactly do you want to place the Adsense (before, after title etc...)

The second part is not related to Adsense, right? It sound like you could just use the "Recent Posts" widget for that? A list of posts in the sidebar, and when you click on any link it goes to the single post page of that post? Or you don't want to show the recent posts, but specific posts?
  #4  
Old Feb 18, 2009, 02:59 PM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Hi Flinn,
Thanks for your response. I would like the ad block to be after the title and either above the content or within the top of the content on the left side.I got ads to show up using the "HTML/CSS inserts" box at the themes options page, but only above the header or below the footer, not within the content area.
My sites going to be an informational site about "natural health remedies and cures" and will have a lot of single post pages on each specific illness, so I want the ads to show up with the full post only, no summaries at all except perhaps in the feed.
I can put links to the pages via the the "text or HTML" widget although it would be nice if there was an easier way.
Thanks so much for your help. I don't have much experience working with HTML or CSS which was why I decided to use your theme, as well as it's good looks!
  #5  
Old Feb 18, 2009, 03:51 PM
Flynn's Avatar
Flynn
 
3,768 posts · Oct 2008
Munich, Germany
This should add an Adsense ad inside the top left of the post body on each single post page:

At the bottom of /atahualpa/functions.php add the following code, without adding/causing any blank line or blank space at the bottom of functions.php (or anywhere else in functions.php, outside of opening and closing PHP tags <?php ... ?>).
PHP Code:
<?php        
function bfa_add_adsense($post_body_content) {
    
$adsense_ad '<div class="bfa-adsense">
    PUT 
    YOUR 
    WHOLE 
    ADSENSE 
    CODE 
    HERE
    </div>'
;
    if ( 
is_single() ) {
        if (
strpos($post_body_content,'%adsense%')!==FALSE) {
            
$post_body_content str_replace('%adsense%'$adsense_ad$post_body_content);
        } else {
            
$post_body_content $adsense_ad $post_body_content;
        }
    }
    return 
$post_body_content;
}
add_filter('the_content''bfa_add_adsense');
?>
And at HTML/CSS Inserts -> CSS Insert, add:

HTML Code:
div.bfa-adsense {
float: left;
display: block;
margin: 1em 10px 5px 0; /* margin 1em top, 10px right, 5px bottom, 0 left */
}

Last edited by juggledad; Mar 19, 2010 at 06:55 AM. Reason: Fixed code, should work now
  #6  
Old Feb 18, 2009, 06:39 PM
Jerry's Avatar
Jerry
 
65 posts · Feb 2009
The beautiful Pacific Northwest USA
Thanks Flinn, I'll see if I can get it done.
  #7  
Old Jul 24, 2009, 06:30 PM
adum's Avatar
adum
 
85 posts · Jun 2009
Quote:
Originally Posted by Flynn
This should add an Adsense ad inside the top left of the post body on each single post page:

At the bottom of /atahualpa/functions.php add the following code, without adding/causing any blank line or blank space at the bottom of functions.php (or anywhere else in functions.php, outside of opening and closing PHP tags <?php ... ?>).
PHP Code:
<?php        
function bfa_add_adsense($post_body_content) {
    
adsense_ad '<div class="bfa-adsense">
    PUT 
    YOUR 
    WHOLE 
    ADSENSE 
    CODE 
    HERE
    </div>'
;
    if ( 
is_single() ) {
        if (
strpos($post_body_content,'%adsense%')!==FALSE) {
            
$post_body_content str_replace('%adsense%'$adsense_ad$post_body_content);
        } else {
            
$post_body_content $adsense_ad $post_body_content;
        }
    }
    return 
$post_body_content;
}
add_filter('the_content''bfa_add_adsense');
?>
And at HTML/CSS Inserts -> CSS Insert, add:

HTML Code:
div.bfa-adsense {
float: left;
display: block;
margin: 1em 10px 5px 0; /* margin 1em top, 10px right, 5px bottom, 0 left */
}
Is adding this different from 3.4.1? I get errors every time I try to add it and have to upload a clean functions php file to get wordpress working again.
  #8  
Old Feb 5, 2010, 06:33 PM
adum's Avatar
adum
 
85 posts · Jun 2009
Quote:
Originally Posted by Flynn
This should add an Adsense ad inside the top left of the post body on each single post page:

At the bottom of /atahualpa/functions.php add the following code, without adding/causing any blank line or blank space at the bottom of functions.php (or anywhere else in functions.php, outside of opening and closing PHP tags <?php ... ?>).
PHP Code:
<?php        
function bfa_add_adsense($post_body_content) {
    
adsense_ad '<div class="bfa-adsense">
    PUT 
    YOUR 
    WHOLE 
    ADSENSE 
    CODE 
    HERE
    </div>'
;
    if ( 
is_single() ) {
        if (
strpos($post_body_content,'%adsense%')!==FALSE) {
            
$post_body_content str_replace('%adsense%'$adsense_ad$post_body_content);
        } else {
            
$post_body_content $adsense_ad $post_body_content;
        }
    }
    return 
$post_body_content;
}
add_filter('the_content''bfa_add_adsense');
?>
And at HTML/CSS Inserts -> CSS Insert, add:

HTML Code:
div.bfa-adsense {
float: left;
display: block;
margin: 1em 10px 5px 0; /* margin 1em top, 10px right, 5px bottom, 0 left */
}
Finally figured this out...

PHP Code:
function bfa_add_adsense($post_body_content) {
    
$adsense_ad '<div class="bfa-adsense">
    PUT 
    YOUR 
    WHOLE 
    ADSENSE 
    CODE 
    HERE
    </div>'
;
    if ( 
is_single() ) {
        if (
strpos($post_body_content,'%adsense%')!==FALSE) {
            
$post_body_content str_replace('%adsense%'$adsense_ad$post_body_content);
        } else {
            
$post_body_content $adsense_ad $post_body_content;
        }
    }
    return 
$post_body_content;
}
add_filter('the_content''bfa_add_adsense'); 
That's what you gotta at the very end of functions.php, right before
PHP Code:
?> 
. Customize the CSS as Flynn said.

I put some extra conditions, to only put these ads in the content if the post is over a month old. I did that with this:

Replace
PHP Code:
if ( is_single() ) 
with

PHP Code:
if ( !is_page() AND is_single() AND (current_time(timestamp) - get_the_time('U') -
(
get_settings('gmt_offset')))/(24*60*60) > 30 
hope that helps!

Bookmarks

Tags
adsense

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Adsense to Kicker and Content adum Post-Kicker, -Byline & -Footer 2 Jun 22, 2009 09:29 AM
Turn off AdSense on certain pages Jerry Atahualpa 3 Wordpress theme 1 Apr 4, 2009 04:34 PM
AdSense Question Jerry Atahualpa 3 Wordpress theme 1 Feb 21, 2009 04:24 AM
How do I insert an Adsense ad after the first post on the page only? jonco Atahualpa 3 Wordpress theme 2 Feb 15, 2009 09:24 AM
Adsense code in Text widget jonco Sidebars & Widgets 5 Feb 11, 2009 04:18 PM


All times are GMT -6. The time now is 08:33 PM.


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