Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Atahualpa 3 Wordpress theme (http://forum.bytesforall.com/forumdisplay.php?f=2)
-   -   Adding AdSense to content (http://forum.bytesforall.com/showthread.php?t=431)

Flynn Aug 22, 2009 09:21 PM

Header already sent usually means that there is a blank line at the bottom of functions.php

pbennett Aug 29, 2009 12:28 PM

this plugin solves all the adsense problems - it's great:

Whydowork Adsense

If you're working with wordpress, you can just upload it. Otherwise, just google for it. I can put adsense just about anywhere I want.

bkg Sep 6, 2009 03:30 PM

Hi,

(My first post - I'm a new blogger with some programming experience. I love the theme and the active support on the forum.)

I have the same problem as adum #33 and river #34 above - when I make the addition to functions.php things get messed up:

Parse error: syntax error, unexpected '=' in /home/MYUSERNAME/public_html/MYBLOG/wp-content/themes/atahualpa/functions.php on line 533


Here's a part of my functions.php with line numbers added:

PHP Code:

531 <?php        
532 
function bfa_add_adsense($post_body_content) {
533     adsense_ad '<div class="bfa-adsense">
534 <script type="text/javascript"><!-- 
[...the rest of the Adsense code as provided by Google]
545     </div>'
;
546     if ( is_single() ) {
[...
the rest of the code provided by Flynn in #5]
556 ?>

The thing is, even with

PHP Code:

531 <?php        
532 
function bfa_add_adsense($post_body_content) {
533     adsense_ad 'foo';
534     if ( is_single() ) {
[...
the rest of the code provided by Flynn in #5]

the result is the same.

However, if I skip the assignment it won't result in an error:
PHP Code:

531 <?php        
532 
function bfa_add_adsense($post_body_content) {
533     if ( is_single() ) {
[...
the rest of the code provided by Flynn in #5]

But then again, it won't present any ads either... :)

I guess this is why I never will be a great programmer, there is nothing that makes me as frustrated as this.

juggledad Sep 14, 2009 03:35 AM

try this
HTML Code:

533    $adsense_ad = '<div class="bfa-adsense">
note the '$' sign

outofdebtagain Sep 18, 2009 11:49 AM

I am also experiencing the problem with "parse error" when I try to modify functions.php. I have just upgraded to Atahualpa 3.4.1. When I put in the code (exactly as shown without any spaces, etc., or modifications to anything else), it breaks my blog. I couldn't even get into wp-admin to fix anything. Thank goodness I backed up my complete folder that holds my blog via FTP. I tried another suggestion to delete the Atahualpa folder from themes (which it was said should default back to default template), but my blog was still not showing. The only thing that worked was to re-upload via FTP my saved blog folder and overwrite the contents. I am not asking for any help with this, I just wanted to add in that I have experienced the same problem. The really frustrating thing is that I copied and pasted the contents of functions.php into a notepad, in case the added code caused a problem, so I that I could copy/paste back in EXACTLY what was there originally and it didn't help. I even went to another blog I have that uses atahualpa and copied out the functions.php but no dice. The only thing that worked in the end was to re-upload my saved blog folder. I've already deleted and re-uploaded twice today, guess I'll be waiting on getting Adsense to the byline area of my single posts.

outofdebtagain Sep 18, 2009 12:09 PM

BTW, I decided to try the Whydowork Adsense plug-in. I have it working now, it was very easy to install. Just be sure you click on "show adsense to administrator" while working on it, or you won't be able to see if it's working!!

adum Feb 5, 2010 06:33 PM

Quote:

Originally Posted by Flynn (Post 1733)
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!

cattie Mar 2, 2010 09:12 AM

Hi all!
I'm new to this theme and this is my first post in thes forum. I'm trying to add Adsense to the home page of my blog. I don't like to use a plugin for Adsense, and I've added the code to functions.php plus that little piece of code in CSS inserts, and that's working great for posts.

I've tried some of the suggestions here, but can't get anything to work. I did get Adsense to show up on pages, which I don't want. I just want it to be on single posts and the home page.

Any advice is greatly appreciated! :)

juggledad Mar 4, 2010 04:14 AM

This post was originally opened when Atahualpa waas at version 3.2 - it's now at version 3.4.6 with some major changes. One of them is the option 'The LOOP' in the 'Style & edit CENTER COLUMN' area.

you can do all sorts of things here and pretty muck eliminate most of the changes to the code (like function.php) and save yourself having to make those changes again at the next release.

By putting in some simple php logic in the 'Content ABOVE the LOOP' you could have your AD show up at the top of the center area before the posts
HTML Code:

<?php if (is_single() or is_front_page()) { ?> <div class="bfa-adsense">
    PUT 
    YOUR 
    WHOLE 
    ADSENSE 
    CODE 
    HERE
    </div>
<?php }; ?>

should be all you would need. This way the code is stored as one of the Atahualpa options in the DB and will not need to be changed during an upgrade.

juggledad Mar 19, 2010 07:04 AM

NOTE: if you got the error
HTML Code:

Parse error: syntax error, unexpected '=' in /home/djembata/public_html/formula1/wp-content/themes/atahualpa/functions.php on line 669
(the line number could be different) make sure the variable 'adsense_ad starts with a '$' si it was
HTML Code:

    adsense_ad = '<div class="bfa-adsense">
make sure it looks like this
HTML Code:

    $adsense_ad = '<div class="bfa-adsense">
I fixed it in the post #5

juggledad Mar 19, 2010 07:04 AM

NOTE: if you got the error
HTML Code:

Parse error: syntax error, unexpected '=' in /wp-content/themes/atahualpa/functions.php on line 669
(the line number could be different) make sure the variable 'adsense_ad starts with a '$'. it was originally
HTML Code:

    adsense_ad = '<div class="bfa-adsense">
make sure it looks like this
HTML Code:

    $adsense_ad = '<div class="bfa-adsense">
I fixed it in the post #5

juggledad Jun 10, 2010 05:48 AM

I'm closing this thread because it started in version 3.2 and things have changed. The info is a mix of old and new which is confusing even myself! I've opened a new thread to deal with version 3.4.4 and above. see http://forum.bytesforall.com/showthr...4066#post34066


All times are GMT -6. The time now is 10:14 AM.

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