Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Register and display widget area specific for Custom Post Type Archive pages.
<?php
// register the custom post type widget area
genesis_register_sidebar( array(
'id' => 'cpt-archive-sidebar',
'name' => __( 'Custom Post Type Sidebar' ),
'description' => __( 'Display this sidebar on your custom post type archive page.' ),
) );
add_action( 'genesis_before_sidebar_widget_area', 'cpt_genesis_before_sidebar_widget_area' );
/**
* Callback for Genesis 'genesis_before_sidebar_widget_area' action.
*
* If on custom post type archive page, remove default sidebar (widget area).
*
* @author Ryan Meier http://www.rfmeier.net/
* @package Genesis
* @category Widget Area
*/
function cpt_genesis_before_sidebar_widget_area(){
// if not on custom post type archive page, return
if( is_post_type_archive( 'custom_post_type' ) ){
// remove default widget areas if on post type archive pages
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
}
}
add_action( 'genesis_sidebar', 'cpt_genesis_sidebar' );
/**
* Callback for Genesis 'genesis_sidebar' action.
*
* If on custom post type archive page, display cpt widget area
*
* @author Ryan Meier http://www.rfmeier.net/
* @package Genesis
* @category Widget Area
*/
function cpt_genesis_sidebar(){
// if not on custom post type archive page, return
if( ! is_post_type_archive( 'custom_post_type' ) )
return;
// display the post type archive widget area
genesis_widget_area( 'cpt-archive-sidebar' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.