• 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

function to add sidebar to a post type

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 › function to add sidebar to a post type

This topic is: not resolved

Tagged: ss_do_sidebar

  • This topic has 5 replies, 3 voices, and was last updated 4 years, 6 months ago by Brad Dalton.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • November 3, 2017 at 9:19 am #213237
    smallfish
    Participant

    Ive followed several suggestions from around the web to create a function that adds a specific sidebar to a post type. The function is working in that it adds the sidebar ok but i cant get it to remove the widgets that appear in the primary sidebar. The inserted sidebar "contact" is set up in Genesis simple sidebars and works fine

    Any one have a thought as to whats wrong? Here's my function

    If you look at the url the list of FAQ's should be there The categories widget and the one that says "this is the primary sidebar" are in the primary sidebar

    Thanks

    function dsi_update_faq_sidebar() {
    if ( get_post_type() =='faq') { // Here "faq" is a slug name for my CPT
    remove_action( 'genesis_sidebar', 'ss_do_sidebar' ); //remove the default genesis sidebar
    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); // and the default wordpress one not sure about this
    add_action( 'genesis_sidebar', 'dsi_add_contact_sidebar' ); //add an action hook to call the function for my custom sidebar
    }
    }

    //Function to output my custom sidebar
    function dsi_add_contact_sidebar() {
    dynamic_sidebar( 'contact' ); // id of sidebar is contact
    }

    add_action('get_header','dsi_update_faq_sidebar');

    http://digitalsilverimaging.com/wp2017/faq/archival-life-of-prints/
    November 3, 2017 at 11:09 am #213239
    Victor Font
    Moderator

    The code commented as remove the default Genesis sidebar is not removing the default Genesis sidebar. The next line that you have commented as removing the default WordPress sidebar is removing the default Genesis sidebar. Unless you have a customization that is adding a sidebar in a function named ss_do_sidebar, that line is not doing anything. You also don't need the get_header action.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    November 3, 2017 at 7:59 pm #213250
    smallfish
    Participant

    Victor thanks for your comments Ive removed the ss_do_sidebar line I added that because im using simple sidebars and i though that might remove the genesis primary one but your right it doesnt mattter.

    If I remove
    add_action('get_header','dsi_update_faq_sidebar');
    The new sidebar doesnt appear- just the genesis primary.

    What i don't understand is why it's there, shouldn't this

    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );

    remove it

    November 4, 2017 at 9:01 am #213258
    Victor Font
    Moderator

    If you're using the Simple Sidebars plugin, it's very likely overriding the Genesis defaults. The code you're using should work if Simple Sidebars is disabled. I'm not sure how I would do this with SS enabled.


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    November 4, 2017 at 7:29 pm #213273
    smallfish
    Participant

    Was my belief that this line removed the simple sidebar sidebar- I feel like ive used it in the past and see other people talking about it in various functions here and there

    remove_action( 'genesis_sidebar', 'ss_do_sidebar' );

    Not sure why one or the other doesn't do it

    November 7, 2017 at 11:36 am #213363
    Brad Dalton
    Participant

    This works :

    add_action( 'get_header', 'remove_primary_sidebar' );
    function remove_primary_sidebar() {
    
    remove_action( 'genesis_sidebar', 'ss_do_sidebar' );
    
    }
    

    Then you need to add your custom sidebar back using another function.


    2700 Genesis Tutorials

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

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

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2022 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