Site icon WPBrigade

How to create a widget below first post excerpt in Genesis

create a widget below first post excerpt in genesis

Beside having great SEO built in feature, the Genesis Framework also good for customizations and editing even when you’re just a beginner with small amount of coding knowledge. As your blog is growing you’ll be start making money through several sources such as Google Adsense. Having good spots to place those banners are really important. In today’s post, I’m going to show you how to insert any advertising code or a WordPress widget right under the first post in your Genesis child theme. Actually, this will going to take effect on your homepage only.

Let’s get started….

The first thing you need to do is navigate to Appearance > Editor > Open up functions.php of your genesis theme. Then what you want to do is add the following snippet at the end of the template.

//* Ads below first WordPress Post
add_action( ‘genesis_after_entry’, ‘first_post_ads’ );
function first_post_ads() {

global $loop_counter;
$loop_counter++;

if( $loop_counter == 1 ) {

if ( is_active_sidebar( ‘ads’ ) ) {
echo ‘<div class=”ads”>’;
dynamic_sidebar( ‘ads’ );
echo ‘</div>’;
}

}

}

//* Register Ads widget
genesis_register_sidebar( array(
‘id’ => ‘ads’,
‘name’ => __( ‘Ads after post’, ‘post_ads’ ),
‘description’ => __( ‘This is the Ads section after posts.’, ‘post_ads’ ),
) );

Remember ‘genesis_after_entry‘ is action that will be used to hook in the page. To make sure that this is working, you must go to your Widgets area and see if there is a new widget spot added.

Style it

Now you need to decorate your new ads widget to meet your site’s design. I already prepared a quick css code for you. Add it into your stylesheet (style.css).

.ads {
background: #ccc;
margin-bottom: 30px;
padding: 40px;
color: black;
}

I hope that you have found a new “hot spot” to add your Google Adsense ads on, which is right under the first post. Last but not least, I would love to thanks Nhatdong (a good friend of mine) for these snippets.

Exit mobile version