Custom Sidebars for CPT Showing Primary Widgets as Well

Community Forums Forums General Discussion Custom Sidebars for CPT Showing Primary Widgets as Well

This topic is: resolved

This topic contains 6 replies, has 4 voices, and was last updated by  weslinda 1 year, 8 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #31337

    weslinda
    Participant
    Post count: 193

    I’m using the Sermon Manager plugin by WordPress Churches for a client build. The plugin sets up everything under a CPT.  Nice and clean.  I’m replacing the standard sidebar with a custom one, and running into a problem.  Both the widgets in the Primary Sidebar AND my custom sidebar are showing on the page. In one sidebar.  I’m quite confused by what’s causing this.  Below is the code I’m using to call the custom sidebar.
    // Add Sermon Sidebar to Sermons Page
    add_action('get_header','uptown_change_genesis_sidebar');
    function uptown_change_genesis_sidebar() {
    if ( 'wpfc_sermon' == get_post_type() ) {
    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
    add_action( 'genesis_sidebar', 'sermons_do_sidebar' );
    }
    }

    //Function to output my custom sidebar
    function sermons_do_sidebar() {
    genesis_widget_area( ‘sermon-downloads-sidebar’ );
    }


    Loving the Genesis Life!

    #31343

    David Chu
    Participant
    Post count: 1406

    Hi!
    I have one lead for you. If you’re running Genesis Simple Sidebars, that will kill any custom remove_action or add_action sidebar activities. I scratched my head for awhile before figuring this out. Genesis Simple Sidebars is an awesome plugin, but one can have one or the other, not both.

    If that’s not it, you could display get_post_type and see if that’s coming through.

    Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #31344

    weslinda
    Participant
    Post count: 193

    Dave, thanks for the reply, but it’s taking the request to change the sidebar, it’s just combining the custom one with the standard one. That’s where the confusion lies. I am using Genesis Simple Sidebars, but this change is required to affect the sidebar on the archives of a CPT from a plugin.


    Loving the Genesis Life!

    #31346

    surefirewebserv
    Participant
    Post count: 75

    What happens if you remove the code from your functions file? I think the simple sidebars plugin would suffice without the extra code in functions.php.


    SureFireWebServices.com | Genesis Tuts and More
    Genesis Theme Starter Kit | It’s Free

    #31347

    billerickson
    Participant
    Post count: 17

    Two issues:

    You need to remove the function that Genesis Simple Sidebars adds to create a sidebar. That’s what’s causing the extra one
    You should make your function hook in later so that it will catch Genesis Simple Sidebars

    Here’s how I would do it: https://gist.github.com/billerickson/5247346

    You could also simplify this by replacing the last add_action() with the dynamic_sidebar( ‘sermon-sidebar’ ) since you’re already on the genesis_sidebar hook.

    #31350

    David Chu
    Participant
    Post count: 1406

    I’m with ya. :-) And I could be wrong, because I’m not in the guts of your code, but if I’m understanding you, it’s actually doing just what I said: the following bit of code won’t work (because of Genesis Simple Sidebars killing it), so it leaves the regular widget there; Primary Sidebar will stay! That’s my best guess based on experience, and based on what little info I have here.

    [code]
    remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
    [/code]

    Hope that gets you a bit further! Good luck,
    Dave


    Dave Chu · Custom WordPress Developer – likes collaborating with Designers

    #31355

    weslinda
    Participant
    Post count: 193

    Bill,

    Thanks that did the trick. Interesting that it’s pulling widgets from both the primary sidebar and the custom one i’ve defined. This is pretty interesting that it’s doing this.  I like the Simple Sidebars as it gives complete flexibility to the client, but little stuff like this makes it challenging to implement in a clean manner.

    This gets me through the primary issue and puts a piece of knowledge out there that I wasn’t aware of.

    Flamenco, your original point was that it was killing my code, which it wasn’t fully.  It was pulling in the sidebar widgets I wanted, but was combining it with the default sidebar widgets.  That’s what was throwing me.  If it wasn’t working at all, that would have been different.  However, it was GSS causing the hiccup.  Kinda interesting to say the least.  It’s weird. Seems like a bug in GSS if it’s calling both.

    Does anyone know if there is an easy way to tell GSS to default to another sidebar for a custom post type?  Maybe there is a hook / filter in GSS that would allow this?  I can enable GSS for CPTs with ease, but the issue is the core archive page for these CPTs created by other plugins.  There isn’t an admin where I can add the sidebar selector to.

    Anyone know if that’s an option in GSS where I’m not turning it off?  Rather I’m able to tell GSS what sidebar to use for a CPT in my functions file.


    Loving the Genesis Life!

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.