Shortcode, Theme Functions, Wordpress

Insert Adsense Ads anywhere within content in WordPress

0 115

Most of the bloggers use Ad networks for monetizing their blogs. Mostly they look for best ad locations to increase CTR in order to improve their earnings. Mostly you will find ads in sidebars or in header sections. But based on my experience of using ad networks, often i get good CTR by inserting ads within content. So here is a simple wordpress shortcode trick to insert adsense or any ad network ads within content.

1

Know the Code


 
Place the following code to your functions.php file.

function adscode() {
	return '
<div id="ads"><script type="text/javascript">// <![CDATA[
google_ad_client = "ca-pub-XXXXXXXXXXXXXXXX"; 	google_ad_slot = "YYYYYYYYYYY"; 	google_ad_width = 336; 	google_ad_height = 280;
// ]]></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// <![CDATA[

// ]]></script></div>';
}
add_shortcode('ad', 'adscode');

To display the ad, you must use the following shortcode :

[ad]

Let’s break the code :

In the above code, you can see that i have included a DIV element with id=”ads”. It can be useful to add beautiful effects to the ad.

check the sample css code, you can add more css properties to make the ad fit your content perfectly.

#ads {
	background: #EEE;
	padding: 14px 25%;
	border: 1px solid #CCC;
}

Please replace this ad code with yours. You can place code of any Ad network such as Adsense or Buysellads or Adbrite or Amazon affiliate etc.

<script type="text/javascript">// <![CDATA[
google_ad_client = "ca-pub-XXXXXXXXXXXXXXXX"; 	
google_ad_slot = "YYYYYYYYYYY"; 	
google_ad_width = 336; 	
google_ad_height = 280;
// ]]></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// <![CDATA[

// ]]></script>

 

Style Code

Check out some ad code examples:

1

Centered AD


 

 

#ads {
	background: #EEE;
	padding: 14px 25%;
	border: 1px solid #CCC;
}

 

2

AD Floating left


The below CSS is used to float the ad on left side and content on right side. You can see this feature in most of the blogs. Some blogs have BuysellAds just below the title floating left and content floating right. This surely will increase your CTR.

#ads {
	float:left;
	background: #eee;
	border: 1px solid #ccc;
	padding:10px;
	margin: 10px 10px 10px 0px;
}

 

3

Ad Floating right



This following CSS will make the Ad to float on right side and content on left. Mostly i use to see blogs having ads floating on left side just below title. So when search engines crawl, The first element they crawl is ad code. mostly i prefer to have ads on right side. This makes content to appear first on content page.

 


#ads {
	float:right;
	background: #eee;
	border: 1px solid #ccc;
	padding:10px;
	margin: 10px;
}

 

Advanced options

If you have too many ad networks like adsense and buysellads or anything else and want to show multiple ads, even then you can make use of the above trick with some simple modifications.

function bsacode() {
	return '
<div id="bsa"><script type="text/javascript">// <![CDATA[
google_ad_client = "ca-pub-XXXXXXXXXXXXXXXX"; 	google_ad_slot = "YYYYYYYYYYY"; 	google_ad_width = 336; 	google_ad_height = 280;
// ]]></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// <![CDATA[

// ]]></script></div>';
}
add_shortcode('bsa', 'bsacode');

In the above code, you can see that i have changed the function name from adscode to bsacode and similarly ads to bsa in add_shortcode part. Similarly use custom CSS code as well.

Now when you want to show the second ad, you must call it using the following shortcode.

[bsa]
#bsa {
	background: #EEE;
	padding: 14px 25%;
	border: 1px solid #CCC;
}
Feedbacks

Hope the above tutorial will be helpful for you. You can replace the Ad code with any custom banner codes or images which you want to show using shortcodes. If you want any custom feature or want modifications in the above trick let me know.

About the author / 

admin

Related Posts

Popular

Editor’s Pick

  • 70+ Stunning HDR images with useful Photoshop Tutorials

    High Dynamic Range Imaging ( HDRI or just HDR ) is a technique which was developed to produce high dynamic range images from the photographs taken at different exposures of light. In comparison with normal digital imaging techniques HDR imaging techniques can produce a wider range of luminescence between dark and light. The main intention…

  • 25+ Breathtaking examples of Natural sky Photography

    Many times throughout the day you look up to the sky and just see a blue or grey sky without much thought. But on some days, you look out into the distance and see something beautiful, something that captivates the beauty of the sky not seen on a daily basis. This collection of photography that…

  • Ultimate Twitter Tools and resources

    Twitter, the micro-blogging platform that has taken the Internet by storm, has so much to offer the online entrepreneur or personal user, yet is misunderstood by many people. Twitter not only allows you to tell the world “what I am doing right now” via its web interface, but can also be integrated and enhanced by…

  • 6 Handy Tips for Responsive Web Design

    Information Technology and Telecommunication have progressed at a rapid rate in the recent years. The development of smartphones, tablet PCs, notebooks and touch screen enabled android mobile devices in the last decade or so is a testament of how quickly technology has evolved. The invention of these multiple computing platforms has urged website developers to…

  • Designing Blogger Template : Adding Meta Tags

    WordPress users have many powerful plugins such as “All in one Seo” and “Yoast Seo plugin” for adding custom meta descriptions to each and every post/page. Again blogger doesn’t provide a plugin platform or custom fields support to add meta description and tags. Though these days in seo meta keywords and descriptions are given less…