• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

replace default sidebar on Custom Post Type archive and posts

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › replace default sidebar on Custom Post Type archive and posts

This topic is: resolved

Tagged: simple sidebars

  • This topic has 5 replies, 2 voices, and was last updated 8 years, 2 months ago by Davinder Singh Kainth.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • July 8, 2015 at 11:43 pm #158868
    martinduys
    Member

    I 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 #158873
    Davinder Singh Kainth
    Member

    Check these:

    http://www.shilling.id.au/2014/09/03/genesis-simple-sidebars-custom-post-types/

    https://wpbeaches.com/set-sidebar-custom-post-type-genesis/


    Sunshine PRO genesis theme
    Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis Themes

    July 9, 2015 at 12:19 am #158874
    Davinder Singh Kainth
    Member

    Check 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 Themes

    July 9, 2015 at 10:58 am #158917
    martinduys
    Member

    Apologies 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 #158951
    martinduys
    Member

    I 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 #158992
    Davinder Singh Kainth
    Member

    Cool.


    Sunshine PRO genesis theme
    Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis Themes

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘replace default sidebar on Custom Post Type archive and posts’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble