Make WordPress Core

Opened 18 months ago

Closed 5 months ago

Last modified 5 months ago

#22182 closed enhancement (worksforme)

Make core theme customizer section titles filterable

Reported by: dgwyer Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.2
Component: Appearance Keywords: has-patch
Focuses: Cc:


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)

update_section_titles.diff (738 bytes) - added by dgwyer 18 months ago.

Download all attachments as: .zip

Change History (13)

comment:1 scribu18 months ago

  • Cc scribu added

comment:2 DrewAPicture18 months ago

  • Cc xoodrew@… added

+1 for making the labels filterable.

comment:3 sabreuse18 months ago

  • Cc sabreuse added

comment:4 follow-up: greenshady18 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 DrewAPicture18 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.

comment:6 dgwyer18 months ago

  • 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' )

I have tested this and it works well. Very easy to update one or more section titles simultaneously.

Last edited 18 months ago by dgwyer (previous) (diff)

comment:7 dgwyer18 months ago

  • Keywords close removed

comment:8 dgwyer12 months ago

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.

comment:9 obenland5 months ago

  • Keywords close added

IMO there really is no need for a filter here. This does it:


function prefix_customize_register( $wp_customize ) {
        $wp_customize->get_section( 'colors' )->title = __( 'Not Colors. Haha!', 'textdomain' );
add_action( 'customize_register', 'prefix_customize_register' );

comment:10 dgwyer5 months ago

Thanks for the code snippet. If you can update the section title directly then that's the best solution.

Much better than removing/(re)adding an entire section just to alter the title. I don't see any reason this ticket can't be closed now.

Last edited 5 months ago by dgwyer (previous) (diff)

comment:11 SergeyBiryukov5 months ago

  • Keywords close removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

comment:12 SergeyBiryukov5 months ago

  • Resolution changed from invalid to worksforme
Note: See TracTickets for help on using tickets.