26 | Adsense in Content of Posts and Pages for wp3


A flexible way to add google adsense into posts and pages in your wordpress blog.
This appraoch uses shortcodes which are an underused technique of increasing the functionality of themes.
Through the formatting options in the shortcode, the text can flow around the adsense blocks similar as it would happen with inserted images.
Options for the alignment are ‘left’, ‘center’, ‘right’ – anything else will be treated as ‘none’.

The code that needs to be added to functions.php of the theme is shown below:
it is called in the text with: [ a d s e n s e     f l o a t = ' l e f t ' ]

// allowed parameter: 'left', 'center', 'right', 'none';
// other entries will be treated as 'none';
function add_adsense($atts) {
  'float' => 'none',
  ), $atts));
if( $float == 'left' ) $float = ' style=" float:left; margin: 10px 10px 5px 0; "';
elseif( $float == 'center' ) $float = ' style=" display:block; margin: 10px auto; text-align:center; "';
elseif( $float == 'right' ) $float = ' style=" float:right; margin: 10px 0 5px 10px; "';
else $float = '';
$ads = '<span class="adsense "'.$float.'>
<script type="text/javascript"><!--
google_ad_client = "pub-0123412341234123";
/* adsense_in_posts */
google_ad_slot = "1234512345";
google_ad_width = 468;
google_ad_height = 60;
<script type="text/javascript"
return $ads;

add_shortcode('adsense', 'add_adsense');

You can see the result here entered into a passage of ‘lorem ipsum’:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse in libero libero. Morbi porttitor, sapien et aliquam malesuada, augue elit tincidunt tortor, vel convallis orci felis quis turpis. Maecenas sit amet diam ut nibh rhoncus accumsan in eget urna. Vivamus sed tempor odio. Curabitur ultricies ultricies molestie. Maecenas eu nisl elit, vitae auctor eros. Nam quis risus libero. Nunc nec ligula sem. Nullam eget sem sed nisi porttitor imperdiet. Etiam ac sapien sed est vestibulum iaculis et id mauris. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Integer tortor magna, malesuada id imperdiet eu, fringilla eget sapien. Donec augue sem, semper et ultrices a, cursus eget nisl. Duis dui enim, ornare ut facilisis eget, egestas ac orci. Etiam viverra varius erat, id feugiat tellus egestas eget.

Aliquam sem purus, ornare ac tempor nec, accumsan ut felis. In cursus massa vitae mauris iaculis nec semper dui commodo. Proin fermentum, lacus ut accumsan scelerisque, orci dui sodales arcu, ac mollis neque odio id turpis. Mauris sagittis tincidunt ultricies. Sed diam ipsum, posuere quis scelerisque et, malesuada quis orci. Mauris nec lectus ac nibh interdum aliquet.

PS: I found more examples of shortcodes in tuttoaster.com

This entry was posted in Tips & Tricks, WordPress and tagged , , , , , . Bookmark the permalink.

10 Responses to Adsense in Content of Posts and Pages for wp3

  1. Pingback: Video:Add Adsense In Posts Using Functions In Wordpress.3.0 |


    28/05/2011 | […] adsense ads in posts or pages using functions code in functions.php that I found while surfing from this article…

  2. g2viruz comments:

    Will this code go at the bottom of functions.php?

    • alchymyth replies:

      yes, that is a possible place to position the code.

      good luck

      • Hanna replies:

        I finally got the coralmotters blog to link to my Adsense account. Part of the problem was that my publisher ID was not correct and all attempts to edit it did not work.Maybe this will help others who are trying to link their blog to an existing Adsense account. First I deleted the old Adsense page element (the one that did not link to the publisher ID of my Adsense account). Next, I added a new Adsense element. When prompted I added my account information. This time it grabbed my correct publisher ID. I think the previous error in my Adsense identity arose from the beta blogger days. However, the EDIT link (if you’re trying to change the adsense ID) did not work. Good luck!

  3. Capricorn  comments:

    adsense is of course the best ppc program. they pay the highest ~*`

    • Sam replies:

      AdSense does pay the highest but you should still test other methods of earning money to see which one brings in the most money.

      Try testing with CPA offers, clickbank products, amazon affiliate, ebay affiliate…

      You should always be testing different monetization strategies.

  4. Paige Price comments:

    Adsense is a great dollar earner if you don’t have a stable job`:,

  5. Pingback: Tweets that mention TransformationPowerTools » Adsense in Posts and Pages for wp3 | for personal growth and transformation -- Topsy.com


    24/06/2010 | […] This post was mentioned on Twitter by Mark Sumpter, Daily Choices. Daily Choices said: TransformationPowerTools » Adsense in Posts…

  6. Pingback: Hello to Inspirational Motivation | %The Conversation Circle%


    24/06/2010 | […] TransformationPowerTools » Adsense in Posts and Pages for wp3 | for personal growth and transf… […]

  7. Pingback: TransformationPowerTools Adsense in Posts and Pages for wp3 ... | Intenseblog.com


    24/06/2010 | TransformationPowerTools Adsense in Posts and Pages for wp3 …… …e adsense into posts and pages in your wordpress blog. This…

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


This site uses Akismet to reduce spam. Learn how your comment data is processed.