Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active February 3, 2016 05:48
Show Gist options
  • Save srikat/3baf0500abe26b841718 to your computer and use it in GitHub Desktop.
Save srikat/3baf0500abe26b841718 to your computer and use it in GitHub Desktop.
Random ad after every second post in Genesis.
add_action( 'genesis_after_entry', 'google_ad' );
/**
* Insert one random ad after every second post.
*
* Scope: Posts page and all category archives.
*
* @author Sridhar Katakam
* @link http://sridharkatakam.com/display-random-ad-every-second-post-genesis/
*/
function google_ad() {
if ( ! ( is_home() || is_category() ) ) {
return;
}
if ( ! function_exists( 'dfads' ) ) {
return;
}
global $wp_query;
if( ($wp_query->current_post % 2) == 1 ) {
echo dfads( 'groups=50&limit=1&orderby=random&container_class=adsense' );
}
}
.adsense {
margin-bottom: 60px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment