Google Adsense
-
Hello-
I’d like to add some Adsense ads in either my header or below the the forum listing on the main page. Pasting Google’s code in the header doesn’t seem to play nicely. Any ideas? Sample syntax, perhaps, from those who have already done it?
Thanks!
-
I’d advise against using header.php, because your header is also shown on non-content pages such as 404’s; something which is disallowed in the adsense T’s and C’s.
I did it by writing a small plugin, which you’re welcome to. Just create a
my-plugins
folder within your bbpress root folder, paste the text below into the file and save it asbbpress-adsense.php
, upload it to your server and an advert will appear on every topic.From there on you have the basics for changing the advert to whatever you prefer.
<?php
/*
Plugin Name: Simple bbPress Adsense
Plugin URI: http://boakes.org/talk/tags/bbpress-adsense
Description: An plugin that includes an adsense advert just above the content on the topic page.
Author: Rich Boakes
Version: 0.1
Author URI: http://boakes.org
License: GPL
*/
class bb_adsense {
function wide_advert() {
?>
<div class="bbpress-adsense" style="text-align:center;">
<!-- Paste your advert below this line -->
<script type="text/javascript"><!--
google_ad_client = "pub-9050338238897291";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel = "5984252204";
google_color_border = "FFFFFF";
google_color_bg = "EEEEEE";
google_color_link = "990000";
google_color_text = "333333";
google_color_url = "999999";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- Paste your advert above this line -->
</div>
<?php
} // function wide_advert
} // class bb_adsense
// adds the footer so the javascript is loaded
add_action('under_title', array('bb_adsense','wide_advert'));
?>
I like this, but I want my adds to show AFTER each first post.
So like:
Post: Hi I need help bla bla
google adsence
First reply: do like this bla bla
Sec reply: or like bla bla
Etc
How to do that?
And is there also a page to maintain your adsence? Like how many click etc in the admin area?
Greetz
Hi Null, to do that you need to change your template a bit and create a new hook, which is dead easy, and a testament to the flexibility of the event model that underpins both WP&bb.
- Copy
topic.php
frombb-templates
intomy-templates
(you may need to create this folder). - Find the for loop near line 29 – it will read something like this:
<?php foreach ($posts as $bb_post) : $del_class = post_del_class(); ?>
- Immediately before it (outside the loop, but inside the
<?php
) add the line$need_to_show_ad=true;
- Then change the line
<?php bb_post_template(); ?>
to read<?php bb_post_template(); if ($need_to_show_ad) { do_action('showadvert'); $need_to_show_ad=false; } ?>
- Finally, change the action in the plugin so it fires on your newly created hook
add_action('showadvert', array('bb_adsense','wide_advert'));
… and an admin page? Maybe when bbPress matures!
I almost understood that last part.
-edit-
oops! read it again and it made sense. thanks.
When i post, edit or delete somethin i get this error
Warning: Cannot modify header information – headers already sent by (output started at /home/disiern/public_html/enblogeo/foro/my-plugins/bbpress-adsense.php:39) in /home/disiern/public_html/enblogeo/foro/bb-includes/pluggable.php on line 160
how can i solve this??
Hi Disier, did you make any other changes other than add the plugin as above? Do you have other plugins installed? Which hook did you use (i.e. what does your add_action line say)?
im using the latest version 0.75, and the only plugin the i have is allow image.
I uninstalled right now because when my friend register in my board and try to login we get that error and canĀ“t login i will delete allow image to see if that plugin is the one of the trouble
Sorry I fix it the problem was here:
a the end of the plugin
<?php
} // function wide_advert
} // class bb_adsense
// adds the footer so the javascript is loaded
add_action(‘showadvert’, array(‘bb_adsense’,’wide_advert’));
?>
in the last line was needing an space after array(‘bb_adsense’,’wide_advert’)); i dint give an space so the ?> was giving the problem thanks anyway
The add_action( ‘under_title’ .. ) part has me curious. Where does the ‘under_title’ come into play? I was trying to find it in my bbpress code. I want to add a wide 250×250 block for example under ‘Add this topic to your favorites’ on the left of the tags column.
http://www.grindhouse.com/forums/topic/26?replies=1
How can I accomplish this?
This plugin causes an error when I try to delete users. I get the following message:
Warning: Cannot modify header information – headers already sent by (output started at /home/jkuno/public_html/seattlecondoreport/forums/my-plugins/bbpress-adsense.php:43) in /home/jkuno/public_html/seattlecondoreport/forums/bb-includes/pluggable.php on line 168
Any ideas?
Look for blank lines or spaces before the starting
<?php
and after the ending?>
as they can cause that problem.Can’t get the system working on my blog, other colors?
InactiveI did everything from earigrey’s post and it does nothing. My main concern is since he asks for it to be put in my-template folder how is the software supposed to know that those files are there. So i just replaced the topic file in the template directory. How do i reference the adsense code so the page knows to look there?
This is a great adsense plugin:
http://www.2diabolos.com/blog/plugin-bbpress-adsense-injection/
thanks @mark8barnes
It is indeed very nice, just tried it.
I’m a bit scared messing around with the adsense code.
Mmm, i was looking for this plugin, but this one isn’t working anymore:
adsense injection is a great plugin , when showing ads, its displaying “array” and ads
ie
array
google adsense ads
Thanks,
phani
Is it possible to do a membership model where a paying user can have no ads?
- Copy
- You must be logged in to reply to this topic.