WP SITES

2952 Tutorials & 191 Plugins

6 Ways To Code After Post Widget In Genesis

In this post, i’ll provide you with 3 different code snippets you can use to create after post content widgets in all Genesis child themes.

Below you’ll find the different code StudioPress child themes contain for adding widgets.

There’s 2 steps to adding widgets in any theme:

1. Register New Widget
2. Function To Hook in New Widget

The code below is for registering a new widget in your child themes functions.php file. It can be used with all code snippets that include functions to hook in widgets in different theme locations.

Register New Widget

/** Register widget areas */
genesis_register_sidebar( array(
	'id'				=> 'new-widget',
	'name'			=> __( 'New Widget', 'child theme name' ),
	'description'	=> __( 'This is the code for registering a new widget in your functions file.', 'child theme name' ),
) );

Once you’ve added the above code in your functions file to register a new widget, there’s many different code snippets you can use to hook in your new widget.

You only need to choose one of these functions to hook in your widget.

Note: All PHP code uses the new Genesis 2.0 loop hooks

Five Functions Which Hook In Widgets

// Hooks after-post widget area to single posts
add_action( 'genesis_entry_footer', 'widget_after_post', 15  ); 
function widget_after_post() {
	if ( is_single() && is_active_sidebar( 'new-widget' ) ) {
		echo '<div class="after-post"><div class="wrap">';
		dynamic_sidebar( 'new-widget' );
		echo '</div></div>';
	}
}

The above code is used to add a new widget which displays after your post content on all single posts.

Its used in the Metro child theme.

/** Add after post ad section */
add_action( 'genesis_entry_footer', 'widget_after_post_ad', 9 ); 
function widget_after_post_ad() {

    if ( is_single() && is_active_sidebar( 'new-widget' ) ) {
    	echo '<div class="after-post">';
		dynamic_sidebar( 'new-widget' );
		echo '</div><!-- end .new-widget -->';
	}

}

The above code is also used to add a new widget after the post content on all single posts.

Its used in the Backcountry, Magazine and several other StudioPress child themes. This is the most commonly way widgets are coded for use in Genesis child themes.

/** Add the after post section */
add_action( 'genesis_entry_footer', 'widget_after_post', 5 );
function widget_after_post() {
	if ( ! is_singular( 'post' ) )
	return;
	genesis_widget_area( 'new-widget', array(
		'before' => '<div class="after-post widget-area">',
	) );
}

Again, the above code is also used to add a new widget after the post content on all single posts.

Its used in the Eleven40 and Streamline child themes.

add_action( 'genesis_entry_footer', 'custom_before_footer_newsletter_box' );
function custom_before_footer_newsletter_box() {

	genesis_widget_area( 'newsletter', array(
		'before' => '<div id="newsletter"><div class="wrap"><div class="newsletter">',
		'after' => '</div></div></div>',
	) );
	
}

This code is used to create an after post newsletter widget in several StudioPress child themes.

And here’s the new way you should code after post widgets in Genesis 2.0 HTML enabled child themes.

add_action( 'genesis_entry_footer', 'widget_after_post', 5 );
function widget_after_post() {
	if ( ! is_singular( 'post' ) )
	return;
	genesis_widget_area( 'new-widget', array(
	'before' => '<div class="after-post widget-area">',
        'after' => '</div>',
	) );
}

Use Built in After Post Widget

Genesis now includes a built in function which enables you to add 1 line of PHP code to the end of your child themes functions file to display the after entry widget area:

add_theme_support( 'genesis-after-entry-widget-area' );

Positioning Priority

You can change the 3rd parameter for positioning priority in each action simply by changing the number.

add_action( 'genesis_entry_footer', 'widget_after_post', 5 );

The example above uses a priority of 5.

$priority
(optional) Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.

Default: 10

Learn more about how to use the 3rd parameter for positioning priority.

Conclusion

So whats the best code to use?

I like to try them out on a local installation and see which one works the best on the theme i’m using.

3 responses to “6 Ways To Code After Post Widget In Genesis”

  1. […] different PHP code you can use to create after post widgets in […]

  2. Please let me know if you’re looking for a article author for your site. You have some really good articles and I feel I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some articles for your blog in exchange for a link back to mine. Please shoot me an e-mail if interested. Regards!

    1. Brad Dalton Avatar
      Brad Dalton

      Hello Callum

      You are welcome to send me your content as long as its focused on WordPress.

Was This Tutorial Helpful?