Troy Templeman
Troy Templeman

Reputation: 285

Move widget area to another section in WordPress Customizer and add controls to it

I'm trying to move a widget area I have set up. It automatically displays in the Customizer's "Widgets" panel as it should but I would like to move it to another section that I have added.

So far, the below code is the closest I've found but unfortunately it causes an error in debug mode. Also, it only puts it in panel and I would like to put it in a section (which is inside a panel). I tried changing ->panel to ->section with no success.

Is there a way around this or another way of doing it? Once done, is there a way of adding controls to this section, in addition to the widgets?

add_action( 'customize_register', 'my_widget_area_move_widget_area' );
function my_widget_area_move_widget_area () {
    global $wp_customize;
    $wp_customize->get_section ('sidebar-widgets-my_widget_area')->panel = 'my_panel';
    }

Upvotes: 0

Views: 498

Answers (1)

JoeMoe1984
JoeMoe1984

Reputation: 2032

In order to change where a widget area is located within the customizer you would want to use the customizer_widgets_section_args filter. With this filter you can customize the customizer options for the widget.

add_filter('customizer_widgets_section_args', 'customizer_custom_widget_area', 10, 3);

function customizer_custom_widget_area($section_args, $section_id, $sidebar_id) {

    if( $sidebar_id === 'my_widget_id' ) {
        $section_args['panel'] = 'my_panel';
    }

    return $section_args;
}

Upvotes: 3

Related Questions