ThemeShaper Forums » Thematic

[closed]

Inserting Adsense code inside main content?

(13 posts)
  • Started 11 years ago by sunlamp
  • Latest reply from Chris
  • This topic is not resolved

Tags:

  1. sunlamp
    Member

    Hi

    I'm trying to add an unobtrusive Advsense text ad underneath the title of each post on my blog.

    It's not a widgetable area, as far as I can tell.

    So used the bit of code below. Unfortunately it makes my title text disappear.

    Can anyone help?

    Thanks in advance
    david

    'function adsense_title() {?>
    <script type="text/javascript"><!--
    google_ad_client = "pub-7072830118301977";
    /* iib: top of content */
    google_ad_slot = "4908871098";
    google_ad_width = 468;
    google_ad_height = 15;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    <? }
    add_filter ('thematic_postheader', 'adsense_title');'

    Posted 11 years ago #
  2. Hi,

    you can't filter it this way :)

    It should look like this:

    function adsense_title($content) {
    
        $content .= "\n" . '<script type="text/javascript"><!--google_ad_client = "pub-7072830118301977";' . "\n";
    		$content .= '/* iib: top of content */' . "\n";
    		$content .= 'google_ad_slot = "4908871098";' . "\n";
    		$content .= 'google_ad_width = 468;' . "\n";
    		$content .= 'google_ad_height = 15;' . "\n";
    		$content .= '//-->' . "\n";
    		$content .= '</script>' . "\n";
    		$content .= '<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>' . "\n";
    		return $content;
    		}
    add_filter ('thematic_postheader', 'adsense_title');

    .. code is untested and without any warranty ;)

    Chris

    Posted 11 years ago #
  3. bigtoe
    Member

    Hi. Would appreciate some assistance with this.

    I've been trying to implement this, but with an adsense plugin called "Advertising Manager" (used to be adsense manager).

    The problem is the ad is appearing above the title. I know almost 0 PHP, and hacking it on my own has been an exercise in frustration. Here's the code I have which probably has issues of its own.

    function adsense_title($content) {
    
        $content .= "\n" . advman_ad('Google Adsense 01') . "\n";
    
        return $content;
      }
    add_filter ('thematic_postheader', 'adsense_title');

    Any help would be great. Thanks.

    Posted 10 years ago #
  4. Hi,

    sounds like the function call echoes the result instead of returning the value.

    Let's see .. 'Advertising Manager' supports shortcodes .. try this one:

    function adsense_title($content) {
    
        $content .= "\n" . do_shortcode('[ad#name]') . "\n";
    
        return $content;
      }
    add_filter ('thematic_postheader', 'adsense_title');

    Change 'name' to the name of your ad.

    Chris

    Posted 10 years ago #
  5. bigtoe
    Member

    Hi Chris. Thanks for the reply.

    Pasted the code, and I don't see the ad, just "[ad#name]" below the title.

    Just to clarify, with the code I pasted in the first post, the ad shows up, just in the wrong place; above the title instead of below it.

    The odd thing is if I replace the adsense code that works, advman_ad('Google Adsense 01'), with plaintext, the plaintext shows up in the right place.

    Working on this for 2 days now, driving me nuts. Thanks.

    Posted 10 years ago #
  6. Have you changed 'name' to a valid ad name?

    Posted 10 years ago #
  7. bigtoe
    Member

    Yup, changed 'name' to a valid ad name, and tested it in a post. Any ideas?

    If this gets too complicated, I'm willing to paste code direct into the template files, just don't know where exactly.

    Thanks for the quick responses.

    Posted 10 years ago #
  8. Will test it here on my machine.

    Posted 10 years ago #
  9. bigtoe
    Member

    Thanks mucho Chris.

    I'll be here waiting patiently, hitting F5 in between looking at code.

    Posted 10 years ago #
  10. Yikes .. the plugin has something that looks like a shortcode, but it isn't. No wonder that my code isn't working.

    .. this code is working:

    function my_ad($name = false)
    {
    	global $advman_engine;
    
    	$ad = $advman_engine->selectAd($name);
    	if (!empty($ad)) {
    		return $ad->display();
    	}
    }
    
    function adsense_title($content) {
        $content .= "\n" . my_ad('Test') . "\n";
    
        return $content;
      }
    add_filter ('thematic_postheader', 'adsense_title');

    Chris

    Posted 10 years ago #
  11. .. and don't even think about touching the Thematic Core ;)

    Posted 10 years ago #
  12. bigtoe
    Member

    Wow. That code works. Thanks mucho, been tearing my hair out for 2 days now, really frustrating when a lack of PHP skills is holding back a project.

    If you have a minute, would you be able to explain that code very briefly? If not, no worries. Anybody know of a nice "PHP for dummies" resource online? Always good to know some PHP when working with a CMS.

    All I have left to do now is put google search in the header, and my migration from Drupal to Wordpress is done. Yay. Thanks again Chris.

    Posted 10 years ago #
  13. No problem .. this is basically the original code from the plugin, it'll search for the Ad name, store the needed code (java script) into $ad, checks if $ad contains data and then .. important .. returns the value instead of doing the echo thing.

    If something is echoed in a filter function the echo will take place before the filter returns its data and before this data is displayed. That's the reason why you had your ad always on top of the post title.

    Posted 10 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.