The WordPress Theme Customization API indicates that there are a number of existing pre-built customizer sections available for the theme developer.
If you want to use any of the existing, built-in ones, you don’t need to declare them with add_section(). Instead, refer to them by name. The following sections are built-in:
- title_tagline
- colors
- header_image
- background_image
- nav
- static_front_page
Refer to them by name? Huh, what does that even mean? To understand this more, I created the simplest theme on the planet. Here’s my style.css:
/*
Theme Name: Minimal ZZ Test Theme
Author: zipzit
Description: An absolute minimal theme, intended to test Theme Customization API
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags:
Text Domain: zz-test-theme
*/
body{
background-color: blue;
}
and index.php:
<?php ?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Simple Web Page</title>
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
</head>
<body>
<h1> this is a test </h1>
</body>
</html>
That’s the entire theme. There is no functions.php file.
When I went to the wp-admin panel, Appearance –> Customize I get the following TWO (out of six possible) sections displayed:
How does one “refer” to the section by “name”? What pulls the canned choices into the wp-admin customize panel? And my real question is: how can you hide a pre-existing choice when overriding a theme (with a child theme.) We definitely don’t want our future admins the chance to change things they shouldn’t be. (Yes, I know we can utilize the admin permission system to hide elements, but that’s not my question…)
Anybody been here before? Many thx.
Edit/update:
Here’s my exact situation. I do lots of websites, often using a child theme to modify an existing theme that gets me sorta close. I’m looking for a very simple, non-bloated bootstrap theme. I found devdmbootstrap3 which I’m pretty impressed with. The only problem is that theme generates a bunch of customization selections that we don’t want to display (colors, header image, background image). I can’t figure out what populates those elements. There is no add_section() calls in the functions.php file. I’ve been thru that file (and the entire theme, including theme-options.php) pretty carefully. Again, I think my issue is not understanding the words “refer to them by name”. I just don’t see where those items are called.
Hmm.. as I think about this, I can certainly install wordpress core and that template inside a localhost server, then step thru the code debugger style to find what call actually creates those elements. Ugh.
Any other ideas? Again, thx.
1 Answer
The default controls are registered in WP_Customize_Manager::register_controls()
, which is hooked to customize_register
. This action is fired in another method, wp_loaded()
, which is hooked to the action of the same name.
To remove these default controls, use your own handler on customize_register
with a later priority, so that it runs after register_controls()
has added them:
function wpse_185386_remove_customize_controls( $wp_customize ) {
$wp_customize->remove_section( 'title_tagline' );
}
add_action( 'customize_register', 'wpse_185386_remove_customize_controls', 50 /* Priority */ );