Hiding a Theme Customization Section

Here’s the quick answer:

function my_customize_register($wp_customize) {
add_action('customize_register', 'my_customize_register');

Which is what you’d expect, of course. However, this little one-liner gives me the opportunity to point out a few things related to it.

Theme Customization API

If you haven’t heard of it yet, the “Theme Customization API” is an API designed to allow your WordPress theme to be customized/configured through the admin dashboard.
Before the introduction of this API, your options for theme customization/configuration were Slim and None:

  • (Ab)use the WordPress Settings API, by adding your own settings, handling their behavior from the DB to the screen (and back), and throughout the theme;
  • Open the theme files and hack away

If you haven’t looked at the Theme Customization API yet, you should. The API was introduced in WP 3.4 (June’12), and it’s still in place: it seems it will stick around for a while, and it’s worth your time.
Here’s the Codex on Theme Customization API, as a starting point.

Theme Customization Sections and Settings

As you will quickly see when reading about the Theme Customization API, the customization options (settings) should be organized in sections. Typically the Theme Customization screen will display each section as a collapsible element in the vertical bar to the side of the screen, with its children settings within.
With the Theme Customization API you can add new sections and/or settings to the $wp_customize object and give your users the customization they need.

Built-In Sections

WordPress comes with a few sections (and settings) baked in; here’s the current list, with the id for each:

  • Site Title & Tagline (title_tagline)
  • Colors (colors)
  • Header Image (header_image)
  • Background Image (background_image)
  • Navigation (nav)
  • Static Front Page (static_front_page)

See the Codex page for an up-to-date list, of course.
Incidentally, the list of sections seems to be implicitly defined by the calls to add_section found in WP_Customize_Manager->register_controls() (so you might want to check that out from time to time).

The Power and the Responsibility

The WP_Customize_Manager->remove_section($section_id) method should be used with care.

Under some circumstances, it may be your only lifeline. For instance, if you need to add a section that already exists, the WP_Customize_Manager->add_section method will pick up the data regarding the existing section and you may or may not be able to change them. In this case, you may have to first call remove_section and then re-add the section with the new details.

In other cases, you may be meddling in the affairs of wizards, and we know ho that ends..


What do I mean? Well, you might abuse remove_section to remove the built-in sections, which means you are removing core features that the end-user may very well expect or need. For instance:


I just removed the ability for the administrator to easily change the basic WP settings for the Front Page (ie: show the latest blog entries or a static page, and -if the latter- which page).

Remember: It Is All About The People, so this may or may not be the appropriate thing to do. In all cases: thread with care!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s