Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years 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: Customize 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 3 years ago.

Download all attachments as: .zip

Change History (13)

#1 @scribu
3 years ago

  • Cc scribu added

#2 @DrewAPicture
3 years ago

  • Cc xoodrew@… added

+1 for making the labels filterable.

#3 @sabreuse
3 years ago

  • Cc sabreuse added

#4 follow-up: @greenshady
3 years 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?

#5 in reply to: ↑ 4 @DrewAPicture
3 years 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.

#6 @dgwyer
3 years 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 locally and it seems to work well.

Version 4, edited 3 years ago by dgwyer (previous) (next) (diff)

#7 @dgwyer
3 years ago

  • Keywords close removed

#8 @dgwyer
3 years 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.

#9 @obenland
2 years 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' );

#10 @dgwyer
2 years 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 2 years ago by dgwyer (previous) (diff)

#11 @SergeyBiryukov
2 years ago

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

#12 @SergeyBiryukov
2 years ago

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