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:) |
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? |
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? |
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!:) |
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:
HTML Code:
div.bfa-adsense { |
Thanks Flinn, I'll see if I can get it done.;)
|
Hi Flynn,
I finally got some pages done and decided to add the adsense block to it. I think I did everything but don't see the ad. I'm pretty inexperienced with adding code and such so I may have done something wrong. Or perhaps it takes awhile for adsense to show up? Anyway, when you get time-no hurry at all. Thanks Flynn |
Sorry I guess a link to my blog would be a good idea.:)
|
I fixed the code above, and also expanded it a bit. Please try again.
It should add an ad into the top left of the post body on all single post pages. Alternatively you can put %adsense% somewhere into a post and that placeholder be replaced with the Adsense ad (and the default top left ad won't be displayed) To move the ad to the right, change HTML Code:
float: left; HTML Code:
float: right; To put the default ad at the bottom (left or right) instead of the top (left or right) change, in the PHP code above PHP Code:
to PHP Code:
Default LEFT or RIGHT: Adjust CSS Alternative: Put %adsense% somewhere into the post. LEFT or RIGHT will still be adjusted by CSS |
Hi Flynn,
I put the amended code in and unfortunately the ads still don't show up. Sorry Flynn, I can see you're putting a lot of time into this fix so another donation will be on it's way as I realize you aren't under any obligation to help all of us out, and I really do appreciate you're efforts on my behalf. Again, I have very little experience, although it is just copy and paste, not too difficult. Again no hurry, whenever you find the time. Thanks |
The above one is useful for me as well, my first attempt at an Adsense function so don't worry, since you've made a donation as well.
I tried the code and it worked for me. You know that a newly created Adsense code will take a while to display right? So there is not even a blank space for the Adsense ad? I just checked your post here and see an ad http://enaturesremedies.com/uncatego...st-to-see-adds Did you add that differently? |
No, but all my posts are on their own page. So if you open the page on "acne' or "pain management" I want the ads to show up there.
So I would imagine the same code will work if I just move it? |
The above code shows ads on single post pages. To show them on "Page" pages as well, change
PHP Code:
to PHP Code:
|
Thanks Flynn,
You rock!! Did you know that?:p |
Got a chance to read through this and it looks easy enough to implement. Well done.
Is there a way to make the ad only show up on the first post on the homepage (I can't have it show up on every post due to AdSense restrictions)? Also, how would you make the Ad float in the center? Well actually I guess it wouldn't look good if it was centered with text around it, but maybe just plain centered? Would you do "align: center;" instead of float? (Also, I made a small donation, it's not much but I know every bit can help and I plan to donate more later.) Thanks, Adam |
In 3.3.3 you can put this:
<?php if ( !is_single() AND !is_page() AND $postcount == 1 ) { ?> ADSENSE CODE HERE <?php } ?> above this: PHP Code:
PHP Code:
|
I hate to bother you more but I am receiving this error when I try to modify functions.php
Parse error: syntax error, unexpected '=' in ..../wp-content/themes/atahualpa/functions.php on line 691 This is not urgent, so please take your time responding if you have other things to do. p.s. using 3.2, can upgrade if that is the problem |
post #16 is for index.php, not functions.php
|
I know, I am referring to post #5. I will need the 2 codes from post #5 and the code from post #16 to make it work, right?
|
No, post #16 and #5 are different.
#16: Ad after first post on multi post pages #5: Ad inside posts/pages on single post pages and/or static pages |
Oh ok, my misunderstanding.
Is there a way to combine both of those? Ad on just first post with option of it being on page pages or not and positioned inside content? |
You should be able to use both at the same time
If your Adsense code for post #5 contains single quotes ' then you'd have to "escape" those by putting a back slash in front of each single quote \' inside your Adsense code |
Quote:
|
Quote:
2. This code will make the ad appear on the homepage along with the multi and single post pages, correct? 3. I originally had my script placed directly above PHP Code:
eadfrith: I never did figure it out, I plan to mess with the code some more today. |
try using
HTML Code:
<?php if ( !is_single() AND !is_page() AND $postcount =< 2 ) { ?> |
Thanks juggledad. I knew it was something pretty obvious but I am bad at coding.
I guess I'll see if everything works and report back, my blog is just underway and has post scheduled every day for the next week or so but I only have one post up so far, so I'll be able to tell in a few days. |
errr I have a problem already. I moved the script outside the post div and it is still in the same spot which is good, but when I put the php code around it, I had some issues.
When I clicked on the post title, it took me to a totally blank page. Same when I clicked on the categories. When I removed the php from the code everything worked fine again. Not really sure about this... |
Quote:
I feel like the blank page error might have arisen because there is only one post on single post pages? If it is possible to get the ad to appear on single post pages as well, I would like to know how to do that. If there is a fix to get the ad to appear below the first TWO posts without getting the blank page error, that would be great too but I can live with it being below just the first post. |
Try this
HTML Code:
<?php if ( is_single() or (is_page() AND $postcount =< 2) ) { ?> |
I kept getting blank pages when I used "=<" but I got this to work:
PHP Code:
|
Quote:
|
Which errors?
|
Man I forget exactly, but it was something like a white page with just a line of text at the top that said "Unexpected "=" found at line 587". I could reproduce the error if you would like specifics.
|
I get this error too.. the exact error is:
Parse error: syntax error, unexpected '=' in /var/www/MY SERVER PATH HERE/blog/wp-content/themes/atahualpa/functions.php on line 532 |
Make sure you aren't closing the single quotes that wrap the adsense code, pre-maturely:
adsense_ad = '<div class="bfa-adsense"> PUT YOUR WHOLE ADSENSE CODE HERE </div>'; If you have single quotes inside your code, you'll need to escape them by putting a backslash in front of them. You don't need to escape double quotes:adsense_ad = '<div class="bfa-adsense"> PUT YOUR \'WHOLE\' ADSENSE "CODE" HERE </div>'; or wrap your code into double quotes instead of single quotes. In that case you need to escape double quotes, if you have any: adsense_ad = "<div class="bfa-adsense"> PUT YOUR 'WHOLE' ADSENSE \"CODE\" HERE </div>"; |
If anyone out there is interested, I ended up using a Plugin called "Advertising Manager" to get the ad in the content. It's pretty simple to use.
One more question tho...I am editing the center column and if I want something to show up on multi post pages, EXCLUDING the homepage/frontpage, how would I go about that? |
hi Flynn,
Don't mean to hijack this thread but, I can't seem to find the code in the forum on how to add the adsense code on the sidebar. I have been browsing through the forum and I can't seem to find the exact way to insert adsense code on the sidebar. Any help would appreciated. thanks a lot! Em http://techsupporthelp.web44.net |
finaldata,
I use a plugin called "Advanced Text Widget". I don't even think you need that, but just insert the script google gives you into a text box on your sidebar. You have to drag the text box over on the "widgets" page and then put the code in there and hit save. |
I obviously did something very wrong.
I entered the code as you posted, but I thought I was supposed to enter it outside the php ?> Now I get this: Parse error: syntax error, unexpected '=' in /home/collette/public_html/MYSITE.com/wp-content/themes/atahualpa342/functions.php on line 553 I'm locked here. I can't get into my WP dashboard to undo the change. HELP!!! |
So I edited the file in cPanel, and that "seemed" to fix the problem.
But now, when I go into WP admin, I get this at the top of every screen: Warning: Cannot modify header information - headers already sent by (output started at /home/collette/public_html/MYSITE.com/wp-content/themes/atahualpa342/functions.php:553) in /home/collette/public_html/MYSITE.com/wp-includes/functions.php on line 784 Warning: Cannot modify header information - headers already sent by (output started at /home/collette/public_html/MYSITE.com/wp-content/themes/atahualpa342/functions.php:553) in /home/collette/public_html/MYSITE.com/wp-includes/functions.php on line 785 Does anybody have ANY idea what's going on here? I didn't touch the header! Added: and when I try to reset the page options using the admin panel, I get a blank page with the same two messages. Update: Deleted and re-uploaded the whole thing. Still have no idea what happened. |
All times are GMT -6. The time now is 06:17 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.