Displaying Adsense Ads at the start or end of the post content is most preferred setup among majority of publishers. If you have a long article content, then you can experiment by embedding Google Adsense Ad (or other Advertisements) bang in the middle of the content. You can easily implement this by creating quick shortcode and display ads anywhere within post content area.

Create shortcode to display Adsense Ads within post

1. Paste the following code in functions.php file of your WordPress setup.

[cc]
function myads1() {
return ‘



‘;
}

add_shortcode(‘ad1’, ‘myads1’);
[/cc]

Once you paste the above code, make sure you replace the ad code with your own Google Adsense ad code as seen between “Start here” and “End here” tags.

2. Now to insert and display Ads within post, open specific post in the WordPress dashboard. Click on HTML mode button in the editor and then paste [ad1] within post body where you want to show the advertisement.

You can also display multiple adsense ad code blocks using above method by changing function name. For example: for second ad code, just add another set of code with different functions name like use 2 in place of 1 for myads1 and ad1. Besides Adsense, you can also use above method for inserting any other type of ad code.

How to style & position displayed advertisement

1. While adding shortcode [ad1] in the post editor, wrap it with specific class for styling as seen in code below:

[cc]

[ad1]

[/cc]

2. Now add adstyle class code to your style.css file. You can begin by adding following sample code. You can modify it further as per your styling requirements.

[cc]
.adstyle {
background:#f4f4f4;
width:400px;
height:500px;
text-align:right;
float:right;
border:solid 1px #c7c7c7;
}
[/cc]

Above is handy shortcode method to insert any type of advertisment code or banner ad within your post content. Depending on the structure of your post content, you can fit different ad banners at various places within post content for better user response and engagement with ads.

Davinder Singh Kainth

A digital creator with 15+ years of experience in Website Design, Development, SEO, and Content Creation to Podcasting at SmartWebCreators.com with the motto of "Be Smart, Keep Creating". A coach, consultant, and your dear geek friend ❖

1 Comment

  1. MNikolic on January 8, 2013 at 1:06 am

    Man, this is AWESOME! Working, simple, elegant! Thanks a lot for this, cheers!

Leave a Comment