Community Forums › Forums › Archived Forums › Design Tips and Tricks › replace default sidebar on Custom Post Type archive and posts
Tagged: simple sidebars
- This topic has 5 replies, 2 voices, and was last updated 10 years, 6 months ago by
Davinder Singh Kainth.
-
AuthorPosts
-
July 8, 2015 at 11:43 pm #158868
martinduys
MemberI am trying to replace the default sidebar on the pages and archive of a custom post type that I have created called 'reviews' with a custom sidebar that I have created using Simple Sidebars.
The following code added to my functions.php file displays the custom sidebard fine, but does NOT remove the default sidebar.
/*
* Replace the default sidebar on the Reviews pages and archive
*
*
*/
add_action( 'get_header', 'bge_swap_sidebars' );
function bge_swap_sidebars() {if ( is_singular('reviews' ) || is_post_type_archive( 'reviews' ) ) {
remove_action( 'genesis_sidebar', 'ss_do_sidebar' );
add_action( 'genesis_sidebar', 'reviews_sidebar' );
}
}function reviews_sidebar() {
dynamic_sidebar( 'chefsrecipes' );
}I have been going round and round in circles on this and would really appreciate some help.
July 9, 2015 at 12:19 am #158873Davinder Singh Kainth
MemberJuly 9, 2015 at 12:19 am #158874Davinder Singh Kainth
MemberCheck this tutorial - http://www.shilling.id.au/2014/09/03/genesis-simple-sidebars-custom-post-types/
Sunshine PRO genesis theme
Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis ThemesJuly 9, 2015 at 10:58 am #158917martinduys
MemberApologies for ugly code above. I'm reposting:
`/* * Replace the default sidebar on the Reviews pages and archive * * */ add_action( ‘get_header’, ‘bge_swap_sidebars’ ); function bge_swap_sidebars() { if ( is_singular(‘reviews’ ) || is_post_type_archive( ‘reviews’ ) ) { remove_action( ‘genesis_sidebar’, ‘ss_do_sidebar’ ); add_action( ‘genesis_sidebar’, ‘reviews_sidebar’ ); } } function reviews_sidebar() { dynamic_sidebar( ‘chefsrecipes’ ); }July 9, 2015 at 1:31 pm #158951martinduys
MemberI finally found the solution here thanks to David Chu
I am also using Genesis Connecto for Woocommerce and so need to add an additional line:remove_action( 'genesis_sidebar', 'gencwooc_ss_do_sidebar' );
So the full piece looks like this:
function bge_swap_sidebar() { if ( is_singular('reviews' ) || is_post_type_archive( 'reviews' ) ) { remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); remove_action( 'genesis_sidebar', 'gencwooc_ss_do_sidebar' ); add_action( 'genesis_sidebar', 'reviews_sidebar' ); } } function reviews_sidebar() { dynamic_sidebar( 'chefsrecipes' ); } add_action( 'genesis_before_sidebar_widget_area', 'bge_swap_sidebar' );July 10, 2015 at 12:20 am #158992Davinder Singh Kainth
MemberCool.
Sunshine PRO genesis theme
Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis Themes -
AuthorPosts
- The topic ‘replace default sidebar on Custom Post Type archive and posts’ is closed to new replies.