Site logo

[Resolved] removing sidebars from custom post types

Home Forums Support [Resolved] removing sidebars from custom post types

Home Forums Support removing sidebars from custom post types

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #443059
    kate

    I am new to filters and am hoping you can help me adjust this code before I add to php. Using GP 2.0.

    I intend to remove sidebars from 4 custom post types.

    add_filter( ‘generate_sidebar_layout’,’​​km_custom_post_sidebar_layout’ );
    function km_custom_post_sidebar_layout( $layout )
    $post_type = get_post_type( $post_id );
    if $post_type is ​’​​​sfwd-courses​’​, ​’​sfwd-lessons​’​, ​’​sfwd-quiz​’​ or ​’​sfwd-certificates​’​;
    return ‘no-sidebar’;
    // Or else, set the regular layout
    return $layout;

    #443191
    Tom
    Lead Developer
    Lead Developer

    Hi Kate,

    Give this a shot:

    add_filter( 'generate_sidebar_layout', 'km_custom_post_sidebar_layout' );
    function km_custom_post_sidebar_layout( $layout ) {
        $post_types = array( 'sfwd-courses', '​sfwd-lessons', 'sfwd-quiz', 'sfwd-certificates' );
    
        if ( in_array( get_post_type(), $post_types ) ) {
            return 'no-sidebar';
        }
    
        return $layout;
    }
    #443192
    kate

    thanks for that. I thought I needed array, but I wasn’t sure how to use. Great little mouse in your photo!

    #443200
    Tom
    Lead Developer
    Lead Developer

    You’re welcome!

    Haha thanks! If only she was still so little.

    #443332
    kate

    Ah yes, you water them, they grow.

    Thanks that worked and also thanks for the code snippet recommendation. That makes me less nervous.

    side note: since I’m using 2.0, is the GPP plugin also still necessary or are you moving away from that?

    #443339
    Tom
    Lead Developer
    Lead Developer

    GP Premium extends GeneratePress with premium modules, so it will always be necessary 🙂

    #443341
    kate

    got it, thanks

    #443343
    Tom
    Lead Developer
    Lead Developer

    No problem! 🙂

    #712500
    Endre

    Hello Tom!

    I am having the same issue, but in LifterLMS, and intend to get rid of the side bar in quizes. Could you help? Thanks. 🙂

    #712510
    Leo
    Staff
    Customer Support

    Hi there,

    This thread is quite old.

    Can you open a new topic for your question?

    Thanks!

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘removing sidebars from custom post types’ is closed to new replies.