最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

customization - How to remove Customizer's Section and move Control straight to Panel using Child Theme

programmeradmin0浏览0评论

I'm looking for a way to remove the Section font_selection and move the Control body_font_family straight to the Panel font_panel using Child Theme functions.php. Below is the sample CODE from parent theme's customizer.php:

//PANEL
$wp_customize->add_panel( 'font_panel', array(
    'priority'       => 17,
    'capability'     => 'edit_theme_options',
    'theme_supports' => '',
    'title'          => __('Fonts', 'theme'),
) );

//SECTION
$wp_customize->add_section(
    'font_selection',
    array(
        'title'     => __('Font selection', 'theme'),
        'priority'  => 10,
        'panel'     => 'font_panel',            
        )
    )
);

//SETTING
$wp_customize->add_setting(
    'body_font_family',
    array(
        'sanitize_callback' => 'theme_sanitize_text',
        'default' => $defaults['body_font_family'],
    )
);

//CONTROL
$wp_customize->add_control(
    'body_font_family',
    array(
        'label' => __( 'Body font', 'theme' ),
        'section' => 'font_selection',
        'type' => 'text',
        'priority' => 12
    )
);   

I'm looking for a way to remove the Section font_selection and move the Control body_font_family straight to the Panel font_panel using Child Theme functions.php. Below is the sample CODE from parent theme's customizer.php:

//PANEL
$wp_customize->add_panel( 'font_panel', array(
    'priority'       => 17,
    'capability'     => 'edit_theme_options',
    'theme_supports' => '',
    'title'          => __('Fonts', 'theme'),
) );

//SECTION
$wp_customize->add_section(
    'font_selection',
    array(
        'title'     => __('Font selection', 'theme'),
        'priority'  => 10,
        'panel'     => 'font_panel',            
        )
    )
);

//SETTING
$wp_customize->add_setting(
    'body_font_family',
    array(
        'sanitize_callback' => 'theme_sanitize_text',
        'default' => $defaults['body_font_family'],
    )
);

//CONTROL
$wp_customize->add_control(
    'body_font_family',
    array(
        'label' => __( 'Body font', 'theme' ),
        'section' => 'font_selection',
        'type' => 'text',
        'priority' => 12
    )
);   
Share Improve this question edited Feb 28, 2017 at 15:12 Fayaz 9,0172 gold badges33 silver badges51 bronze badges asked Feb 28, 2017 at 12:57 CaracosCaracos 295 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Assuming that the parent theme is running the above code at customize_register priority 10, you just have to add another customize_register action callback that runs afterward, like at 20. However, you cannot move a control to a panel. Controls can only reside inside of sections. To move a control to another section you can use:

add_action( 'customize_register', function ( WP_Customize_Manager $wp_customize ) {
    $wp_customize->remove_section( 'font_selection' );
    $wp_customize->add_section( 'some_other_section', array(
        'title' => __( 'Some other section', 'theme' ),
    ) );

    $body_font_family_control = $wp_customize->get_control( 'body_font_family' );
    if ( $body_font_family_control ) {
        $body_font_family_control->section = 'some_other_section';
    }
}, 20 );

Possible to move widgets control to another section ?

Like sidebar_widgets want to move my_section

$sidebars_widgets_control = $wp_customize->get_control( 'sidebars_widgets-foot_sidebar' );
    if ( $sidebars_widgets_control ) {
        $sidebars_widgets_control->section = 'my_settings';
    }
}, 20 );
发布评论

评论列表(0)

  1. 暂无评论