I've finally started setting up the Theme Customizer in WordPress for my clients. I ran into an issue where the Theme Customizer has certain defaults that not all themes use. It is pretty rare for my sites to include a tagline; for us at BR the brand's tagline is usually included in the logo so we don't need to restate it. It would be very confusing if your theme customizer has an editable tagline that doesn't appear anywhere on the site.
Since this feature only came out this year there is still a lot of bad information running around; yes there is even some misinformation on WordPress Answers. The correct way to remove an entire section is this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// remove section | |
$wp_customize->remove_section( 'section_id'); |
You have to know the section ID that you're removing. You can dig through the HTML on the theme customizer page or you can look at this handy dandy list of the default theme customizer sections.
Removing a control within in section (such as removing a tagline within the Site Title & Tagline section) can be done in exactly the same way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// remove control | |
$wp_customize->remove_control('control_id'); |
As with removing the section above you have to know the ID of the control that you're removing. The easiest way to find a control is to dig through the HTML. Or if you're simply looking to remove the tagline the id is blogdescription.
So you figured out how to remove the tagline from the theme customizer, all done right? Well I thought I was till I looked at the theme customizer and noticed that there is now a section called “Site Title & Tagline” and it only controls the site title with a tagline no where to be seen. Facepalm. Alright – just a little bit further – we just have to rename the section. We can actually just redeclare it with a new name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rename existing sections | |
$wp_customize->add_section( 'section_id' , array( | |
'title' => __('Section Title','mytheme'), | |
'priority' => 20, | |
)); |
The complete code to remove the tagline from the theme customizer and rename the section looks like this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// remove control | |
$wp_customize->remove_control('blogdescription'); | |
// rename existing section | |
$wp_customize->add_section( 'title_tagline' , array( | |
'title' => __('Site Title','mytheme'), | |
'priority' => 20, | |
)); |
Exactly just what I needed for my theme. Thanks. 🙂
No need to redeclare. Use the following:
$wp_customize->get_section('title_tagline')->title = __('Site Title');
where to add this code
Thanks for this – I couldn’t easily find this information in the WordPress codex. I wish they would improve the way they show and organise their documentation as it would make things a lot easier!
This solved our issue – thanks!
Ben