Opened 7 months ago
Last modified 5 weeks ago
#22182 new enhancement
Make core theme customizer section titles filterable
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Appearance | Version: | 3.4.2 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | scribu, xoodrew@…, sabreuse, justin@… |
Description
It would be very useful to be able to modify core theme customizer section titles by making them filterable, or by adding a setter class method to modify an existing section title.
At the moment you can't access a section title directly as it is set to protected.
Example user case scenario is if you needed to add sub controls to an existing section, then the title may need updating to reflect this.
Attachments (1)
Change History (9)
comment:2
DrewAPicture — 7 months ago
- Cc xoodrew@… added
comment:4
follow-up:
↓ 5
greenshady — 7 months ago
- Cc justin@… added
Can you just use the gettext hook? Or, use remove_section() and re-add the section with add_section() with a custom title?
comment:5
in reply to:
↑ 4
DrewAPicture — 7 months ago
- Keywords close added
Replying to greenshady:
Can you just use the gettext hook? Or, use remove_section() and re-add the section with add_section() with a custom title?
I did that to re-order controls but didn't occur to me to try it for changing the section titles. This works for me:
$wp_customize->remove_section( 'colors' ); $wp_customize->add_section( 'colors', array( 'title' => 'New Colors', 'priority' => 40 ) );
Suggest close.
- Keywords has-patch added
I already knew about the remove/add section approach.
If we elect to use class methods, rather than a filter, a more elegant solution would be to add a get/set method to update section title labels rather than having to remove/add sections to update each one individually.
I have uploaded a patch (update_section_titles.diff) to add a class method that accepts an array of key/value pairs of section title id's/labels to update. Using this new method you can update any/all registered section title labels in ONE go, including user defined ones (not just core defined ones).
Usage is simply:
$titles = array( 'title_tagline' => __( 'Section Title and Tagline' ), 'colors' => __( 'Site Colors' ), 'header_image' => __( 'Header Background Image' ), 'nav' => __( 'Navigation Menu' ), 'my_custom_title' => __( 'Updated Section Title' ) ); $wp_customize->update_section_titles($titles);
I have tested this and it works well. Very easy to update one or more section titles simultaneously.
Another reason why this is better than just removing/re-adding the whole section is that I don't necessarily know (or want to know!) how the section was added in the first place.
For example, if I remove/re-add a section and NOT match the other original section attributes exactly (such as priority, capability, theme_supports, description) then it could mess things up, which is not good.
My patch avoids this altogether allowing you to modify all section titles in one go, without affecting anything else.

+1 for making the labels filterable.