Insert Adsense after the first post in Genesis Theme



It is very important to place the at least 3 ads in each and every page of your blog. This will increase the CTR . This is very common question in WordPress and the implementation changes for as the theme changes. It is bit difficult to implement in case of frameworks when compared to general themes. As part of our Genesis Tutorials let us have a look at how to add or insert Adsense slot after the first post in Genesis Theme fact. In fact once you could able to add after first post you can implement the same for after 2nd, 3rd … nth position.

Before stepping further make sure you have created a child theme or using a child theme for genesis. If you don’t know how to create a child theme please have a look at detailed tutorial how to create child theme for genesis.

Login to your WordPress dashboard

Go to Appearnace->Edit

in your funtion.php of your child theme just add the below part of the code and replace the text REPLACE THIS TEXT WITH YOUR ADSENSE CODE with your Adsense code.

add_action('genesis_after_post', 'ad_after_first_post');
function ad_after_first_post() {
global $loop_counter;
if (!is_singular() && $loop_counter == 0) { ?>
REPLACE THIS TEXT WITH YOUR ADSENSE CODE
<?php }}

after the end of your file.

Explanation of code.

Here we are create a simple function ad_after_first_post and calling the function at the position after posts using genesis hooks genesis_after_post. This will enable us to add part of code after first post. In the next line we initiated a global variable which as a loop counter to count the posts. In the next line we checked some true conditions like is_singular to avoid posts on single posts and loop counter == 0 to check for the first posts and finally display you ad code.

If you are looking to insert your ad after 2nd post replace the value of $loop_counter with 1 in the above code and if after 10th post make $loop_counter with 9 in condition

Comments

  1. Hi, is it also possible to add a widget area between posts instead?

  2. Awesome. It almost looks like they purposely complicated genesis themes.

  3. It adds adsense code in the bottom of the post and on home page only not on single posts..

  4. I install codes very rarely, its an good post but this will be the best if you can give us an example of putting on the second post.

Speak Your Mind

*


9 + = twelve