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

Genesis Snippets

A reference for Genesis theme developers

  • Home
  • Archives
  • Search Genesis Snippets

sidebars

Display a custom sidebar on a custom post type

December 28, 2012 By David Wang

Here’s how to replace the primary sidebar on a custom post type. First, register your sidebar. Next, use this code to swap the primary sidebar with the new one you just registered:

// Swap sidebars on CPT pages
add_action('get_header','child_change_genesis_sidebar');
function child_change_genesis_sidebar() {
	if ( is_singular('post_type')) { // change 'post_type' to your CPT slug
		remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); //remove the default genesis sidebar
		add_action( 'genesis_sidebar', 'child_do_cpt_sidebar' ); //add an action hook to call the function for my custom sidebar
	}
}
 
// Output sidebar with the id 'sidebar-custom'
function child_do_cpt_sidebar() {
	genesis_widget_area( 'sidebar-custom' );
}

If you want to display the sidebar on both the single post page and archive page for your custom post type, modify the if statement in child_change_genesis_sidebar() function to include

if ( is_singular('post_type') || is_post_type_archive('post_type') ) {

Credit: Carrie Dils & Travis Smith from How to Use a Custom Sidebar on a Custom Post Type

Filed Under: Genesis Tagged With: custom post type, sidebars, widget areas

Unregister sidebars

March 21, 2012 By David Wang

Don’t need the header right widget area? Or perhaps you don’t need 3 columns for your theme. Then your widget areas a.k.a. sidebars are redundant. Unregister them with the following:

/** Unregister default sidebars */
unregister_sidebar( 'header-right' );
unregister_sidebar( 'sidebar' );
unregister_sidebar( 'sidebar-alt' );

Filed Under: Genesis Tagged With: sidebars, widget areas

Register new widget areas

March 21, 2012 By David Wang

First, register a new sidebar. The before_widget, after_widget, before_title and after_title arguments are optional and allow you to customize the HTML output.

genesis_register_sidebar(
	array(
		'name'=>'Custom Sidebar',
		'id' => 'sidebar-custom',
		'description' => 'This is a custom sidebar',
		'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-wrap">',
		'after_widget'  => "</div></div>",
		'before_title'  => '<h4 class="widgettitle">',
		'after_title'   => "</h4>"
	)
);

Then inject the sidebar into the appropriate hook with genesis_widget_area(). The function conditionally displays a widget area.

add_action( 'genesis_sidebar', 'child_do_sidebar' );
function child_do_sidebar() {
	genesis_widget_area( 'sidebar-custom',
		array(
			'before' => '<div id="sidebar-custom">',
		)
	);
}

See the available arguments for genesis_widget_area() in /genesis/lib/functions/widgetize.php

Update 28 Dec 2012: Replaced dynamic_sidebar() with genesis_widget_area()

Filed Under: Genesis Tagged With: sidebars, widget areas

Primary Sidebar

Brought to you by ClickWP
Buy the Genesis Theme Framework

Who’s behind this?

Hi! I'm David and I'm a big Genesis fan. I've been using it in all my projects and have found it to be super powerful.

I started this site to keep track of all the snippets that I've been using in my projects and so that it's easy for me to find them again instead of digging through my old project files.

Help support this site by buying Genesis with our affiliate links. Thanks!

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 354 other subscribers

Browse Snippets

branding cache comments css custom post type doctype entry footer entry header favicon featured image genesis_custom_loop images internet explorer jetpack loop media menu metabox minify navigation oembed page layouts performance plugin integration post thumbnail shortcode sidebars theme options widget areas widgets WooCommerce WordPress
Everything you need to support your online business
Take WordPress further with the Genesis framework

Copyright © 2025 · Genesis Sample On Genesis Framework · WordPress · Log in