How to: Embed Adsense anywhere on your posts

December 19, 2008 at 8:42 am

Do you ever wanted to get a total control over the way your adsenses ads are displayed? In the following recipe, I’m going to teach you how to be able to use adsense only in the post you want and display the ads where you want.

First, you have to add the following code to your function.php file. Don’t forget to change the adsense code, unless you’d like to display my ads on your own site ;)

function showads() {
    return '<script type="text/javascript"><!--
google_ad_client = "pub-3637220125174754";
google_ad_slot = "4668915978";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
';
}

add_shortcode('adsense', 'showads');

Once you saved the functions.php file, you’re now able to embed your adsense code on your posts and display it exactly where you want. To do so, simply paste the following code on the editor, in html mode:

[adsense]