|
#1
Feb 18, 2009, 02:15 AM
|
|
|
|
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
Feb 18, 2009, 10:43 AM
|
|
|
|
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
Feb 18, 2009, 03:12 PM
|
|
|
|
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
Feb 18, 2009, 03:59 PM
|
|
|
|
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
Feb 18, 2009, 04:51 PM
|
|
|
|
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 07:55 AM.
Reason: Fixed code, should work now
|
#6
Feb 18, 2009, 07:39 PM
|
|
|
|
65 posts · Feb 2009
The beautiful Pacific Northwest USA
|
|
Thanks Flinn, I'll see if I can get it done.
|
#7
Jul 24, 2009, 07:30 PM
|
|
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
Feb 5, 2010, 07:33 PM
|
|
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 . 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!
|
|