0

Since WP 4.5 the way you hide core components from the customizer was changed. Changed from $wp_customize->remove_panel() to customize_loaded_components.

https://developer.wordpress.org/reference/hooks/customize_loaded_components/

The two examples in the above link works but if I try it on any of the other core sections of the customizer such as Site Identity(ID:title_tagline) or Header Image(ID:header_image) it doesn't work.

Works:

function hn_remove_nav_menus_panel( $components ) {
        var_dump($components);
        $i = array_search( 'nav_menus', $components );
        if ( false !== $i ) {
            unset( $components[ $i ] );
        }
        return $components;
    }
    add_filter( 'customize_loaded_components', 'hn_remove_nav_menus_panel' );

Does not work:

function hn_remove_title_tagline_panel( $components ) {
        $i = array_search( 'title_tagline', $components );
        if ( false !== $i ) {
            unset( $components[ $i ] );
        }
        return $components;
    }
    add_filter( 'customize_loaded_components', 'hn_remove_title_tagline_panel' );

I've tried to var_dump($components); as well but can only see nav_menus and widgets in that array which would explain why only those two components can be removed.

Any hints on how to hide the other sections would be appreciated.

1

If you check out the source of WP_Customizer, you'll see there is no title_tagline or header_image at the time the filter runs:

final class WP_Customize_Manager {
    protected $components = array( 'widgets', 'nav_menus' );

    public function __construct() {
        // a bunch of requires

        $components = apply_filters( 'customize_loaded_components', $this->components, $this );
    }
}

Use the customize_register hook to remove the sections after WP has added them:

function wpse_225164_remove_core_sections( $wp_customize ) {
    $wp_customize->remove_section( 'title_tagline' );
    $wp_customize->remove_section( 'header_image' );
}

add_action( 'customize_register', 'wpse_225164_remove_core_sections' );
  • 1
    Thanks @TheDeadMedic I get it now. I assumed the procedure had changed for sections as well as panels but it's only changed for panels. – Brigante Apr 29 '16 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.