3

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:enter image description here

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.

2
  • 1
    The other 4 features rely on your theme declaring support for them in your functions.php, hence why they're not currently visible. Check out this article for a little more information, the first comment also tips at how to remove them. Commented Apr 25, 2015 at 19:27
  • Nope. That's exactly where I started. I will edit my original question with more specifics. I can't figure out where those elements are being 'called' into existence.
    – zipzit
    Commented Apr 25, 2015 at 19:42

1 Answer 1

1

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 */ );
5
  • Wow. Let me play around a bit. I'm curious, what the wpse_big#_ prefix for? Is that how many custom functions you've created in support of this site? Oh, and thank you!
    – zipzit
    Commented Apr 25, 2015 at 20:08
  • Haha, luckily not. If I'd created ~200k snippets for this site I'd be questioning my sanity. It's the ID of the question (check the URL), and it's a syntax that many authors here adopt (the idea being that there's always some reference back to the question if you find the code unedited in the wild). Commented Apr 25, 2015 at 20:11
  • It also saves a lot of headache with copy-pasters who just dump it right in their project - if we start handing out code like generic_function_name it won't be long before they hit a redefine/namespace clash. Commented Apr 25, 2015 at 20:15
  • Way cool. In fact, I can certainly use that technique when I find a reference to a function from this site (or any other), and use that function from within my own code. I've been using comments to describe 'assists' with complete url. I'm glad I asked. Is that technique listed as a best practice anywhere?
    – zipzit
    Commented Apr 25, 2015 at 20:17
  • I would suggest you keep doing the comment method, and keep all your functions "namespaced" with your own unique project prefix. Like I say, we do it as a "failsafe" for people that won't bother - it's always better to have code consistency in your project. Here's the relevant discussion on meta. Commented Apr 25, 2015 at 20:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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