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

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

How To Add The Same Widget On Single Posts & Blog Page

This tutorial provides 2 ways to add a widget area which displays on both single posts and any page using the genesis blog page template.

Here’s the demo video:

1st Solution

Step 1 : Add the following PHP code to the end of your child themes functions.php file:

genesis_register_sidebar( array(
	'id'          => 'blogandsingle-page-widget',
	'name'        => __( 'Blog & Single Widget' ),	
) );

add_action( 'genesis_before_loop', 'single_post_widget' );

function single_post_widget() {

if ( is_active_sidebar( 'blogandsingle-page-widget' ) && is_singular( 'post' ) ) {

    genesis_widget_area( 'blogandsingle-page-widget', array(
        'before' => '<div class="new-widget widget-area">',
        'after'	 => '</div>',
    ) ); 

    }

}

Step 2 : Create a custom page_blog.php file in your child themes root directory and add the following code to the file.

Note: You’ll also need to add a opening php tag to the very first line of the file.

/**
 * @link https://wp.me/p1lTu0-gN7
 * @author Brad Dalton
 */

/*
Template Name: Blog With Widget
*/

add_action( 'genesis_before_loop', 'blog_page_widget' );

function blog_page_widget() {

if ( is_active_sidebar( 'blogandsingle-page-widget' ) ) {

    genesis_widget_area( 'blogandsingle-page-widget', array(
        'before' => '<div class="new-widget widget-area">',
        'after'	 => '</div>',
    ) ); 

    }

}

genesis();

This tutorial has been written in response to this question from a members of the Genesis community:

can anyone help me with conditions for adding the same widget on single posts and the blog page? I can get it to work on single posts but have no luck in adding a condition to get it appear on the blog page

Here’s the 2nd solution for logged in members:

Register for full access

Related Tutorials

  • Target Genesis Blog Page Template

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags