Custom Sidebars

In some case you may want to register an additional sidebar for pages or a custom post type you’ve created. In this article, we’re going to learn how to register and add a custom sidebar to a custom post type.

First, we’re going to register our sidebar by adding the code below to our child-theme’s functions.php

// Custom Sidebar
function prefix_custom_sidebar() {

    register_sidebar( array(
        'name'          => __( 'Custom Sidebar', 'page-builder-framework' ),
        'id'            => 'custom-sidebar',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h4 class="wpbf-widgettitle">',
        'after_title'   => '</h4>'
    ) );

}
add_action( 'widgets_init', 'prefix_custom_sidebar' );

Our new Sidebar should now appear under Appearance -> Widgets and can be filled with content.

In the next step, we’re going to display the sidebar on our custom post type by using a filter.

// Replace the default sidebar with our new custom sidebar on all docs posts
function prefix_do_custom_sidebar( $sidebar ) {

    if( is_singular( 'docs' ) ) {
        $sidebar ='custom-sidebar';
    }

    return $sidebar;

}
add_filter( 'wpbf_do_sidebar', 'prefix_do_custom_sidebar' );

Download Today. It's 100% Free.

You have a best friend, your Page Builder probably should too.

Page Builder Framework

A modern, fast & minimalistic theme designed for the new WordPress Era.

Sign up for the Newsletter

Get notified about the latest updates and feature releases.

We take your privacy seriously! No spam, we promise. See our Privacy Policy
Community
Scroll to Top