• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WordPress Tips, Code Snippets, and How To Tutorials

  • Home
  • Blog
  • Tips
  • Snippets
  • Tutorials
  • Contact

How to add an Adsense Ad after every post in StudioPress Genesis

April 5, 2016 by admin 2 Comments

Google’s Adsense Ads are a great way to earn money from your site’s traffic. Just add this WordPress Code Snippet to the functions.php file in your current WordPress theme in order to add an Adsense Ad after every post in a site running on the StudioPress Genesis Framework.

/**
 * Add Adsense Ad after posts in StudioPress Genesis
 *
 * @author WPSnacks.com
 * @link https://www.wpsnacks.com
 */
function ad_after_posts() {
 if ( is_single() ) {
?>
<strong>Sponsored Links</strong>
<br>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-5636129889821632";
/* WPSnacks_After_Post_Ad */
google_ad_slot = "2107218414";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<?php
}
}
add_action('genesis_after_post_content', 'ad_after_posts');

Just be sure to replace my Adsense Ad code(between the first and last “script” tags) above with your own. In the example above, the section is headed with “Sponsored Links”, which can be changed to what you would like the heading text above your Ad, just be sure you follow Google’s Adsense Guidelines.

If you like this then you should look up more of our WordPress Tips Code Snippets and Tutorials.

Disclosure: There are affiliate links on posts and throughout the website and if you use the links to make a purchase we may earn a commission from it. We link to these companies and their products because of the quality of the companies and not because of the commission we may receive from it.

Disclaimer: The information contained in this website is for general information purposes only and in no event will this website or its owners be liable for any losses or damages associated with your use of our website or content. We recommend that you make a backup of your website before you make updates to it. Click here to see our full Disclaimer.

Filed Under: Code Snippets Tagged With: Ads, Functions.php, StudioPress Genesis

Reader Interactions

Comments

  1. share market says

    June 4, 2012 at 9:44 pm

    The more simpler way will be to use some plugin. Post layout plugin does the task easy, and it has many more features.

    Reply
  2. Emily Murray says

    November 10, 2012 at 5:41 am

    This is great thanks! Is there any way to exclude specific categories or posts that you do not want ads displayed on?

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Hey, We Deliver... Anywhere!

Enter Email Address below to receive our snacks via email:

Join Over 1200 Readers!

Jump To A Random WordPress Tip

Copyright © 2019 • wpsnacks.com