Make WordPress Core

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#27178 closed enhancement (fixed)

Filter Hook for "Default Template"

Reported by: johnstonphilip's profile johnstonphilip Owned by: johnbillion's profile johnbillion
Milestone: 4.1 Priority: normal
Severity: normal Version: 3.8.1
Component: Themes Keywords: has-patch
Focuses: administration, template Cc:

Description

As a theme author, I would really like to give more of a relevant title to the "Default Template" for pages in the "Page Attributes" > "Template" dropdown menu. Unfortunately, this title is hard coded into WordPress so we can't customize it (aside from translating it).

For example, rather than the Default Template simply being called "Default Template", it would be great to be able to say "No Sidebar", or something else which gives more relevance and understanding to the user.

"Default Template" doesn't say anything descriptive about the template at all and is fairly unhelpful.

A simple filter hook in wp-admin/includes/meta-boxes.php on line 664 would allow for this.

The code as it currently is:

<option value='default'><?php _e('Default Template'); ?></option>

The code I would like to see:

<option value='default'><?php apply_filters( 'default_page_template_title',  _e('Default Template') ); ?></option>

Attachments (3)

patch_commit_6b2f61b836b3.patch (1.6 KB) - added by johnstonphilip 11 years ago.
Filter Hooks for "Default Template" Title
patch_commit_93474626d255.patch (2.4 KB) - added by johnstonphilip 11 years ago.
Re-patched as single filter with context and documentation.
0001-Filter-Hooks-for-Default-Template.patch (2.5 KB) - added by johnstonphilip 10 years ago.
This adds a filter hook for the default page template's title in WordPress.

Download all attachments as: .zip

Change History (20)

#1 @johnstonphilip
11 years ago

There was an error in my replacement code. Should actually read as:

<option value='default'><?php echo apply_filters( 'default_page_template_title',  __('Default Template') ); ?></option>
Last edited 11 years ago by johnstonphilip (previous) (diff)

#2 @SergeyBiryukov
11 years ago

  • Component changed from General to Themes
  • Focuses template added; ui removed

#3 @SergeyBiryukov
11 years ago

The string is also used in Quick Edit: tags/3.8.1/src/wp-admin/includes/class-wp-posts-list-table.php#L935.

You can change it via gettext filter:

function change_default_page_template_title_27178( $translated_text, $text, $domain ) {
	if ( is_admin() && 'Default Template' == $text ) {
		$translated_text = 'No Sidebar';
	}

    return $translated_text;
}
add_filter( 'gettext', 'change_default_page_template_title_27178', 10, 3 );

#4 @johnstonphilip
11 years ago

Ah nice! Thanks Sergey. That's a great workaround.

#5 @johnstonphilip
11 years ago

The only thing is that gettext runs thousands of times per page - so adding a check to it isn't the most robust option. It is a great temporary workaround though. Ideally I would still like to see a filter to reduce the strain on gettext. Thoughts?

#6 @DrewAPicture
11 years ago

Since the string is also used in Quick Edit, we could simply pass a context value to the filter for each of the different placements. I agree that filtering via gettext is not ideal.

@johnstonphilip: Interested in giving a patch a go? Happy to assist.

#7 @SergeyBiryukov
11 years ago

The string is used in the same context in both places, so I don't think a separate context is needed for translation. I just meant that if we're going to add a filter, we should do that in both places.

#8 @johnstonphilip
11 years ago

I'm going to try and submit a patch. I've never done it before so wish me luck :P

Before I do, I would be tempted to say that passing a context might not even be enough to differentiate it in all circumstances - that we might want two completely different filters. I'm not totally convinced it's a good idea but I can imagine a scenario which isn't all bad:

For example, if you had a metabox with additional options show up for specific page templates (using javascript) on the main edit screen, those metaboxes wouldn't appear on the Quick Edit screen.

If you wanted to call your default template "No Sidebar (Additional Options Below)", that wouldn't make sense on Quick Edit because those additional options won't be there.

Having two separate different filters would allow it - I just hope it isn't overcomplicating it for rare-use cases.

I'm a big fan of communicating as much to the user in the least amount of words/places.

@johnstonphilip
11 years ago

Filter Hooks for "Default Template" Title

#9 @johnstonphilip
11 years ago

I added the patch. I hope I did it right!

@johnstonphilip
11 years ago

Re-patched as single filter with context and documentation.

#10 @johnstonphilip
11 years ago

  • Keywords has-patch added

#11 @DrewAPicture
11 years ago

  • Keywords needs-patch added; has-patch removed

Thanks for adding the hook documentation in the second patch. Here's some feedback on the docs:

  • The $context parameter description could probably use a little work.

So instead of "The context of where this title is displayed. Here, it's 'meta-box'. When displayed on Quick Edit, its value is 'quick-edit'."

Maybe go with something more like:

"The context of where the option label is displayed. Possible values include 'meta-box', and 'quick-edit'. Default 'meta-box'."

  • Text should be wrapped around ~80 characters width, and the lines 2+ would each be align with the first character of the description using spaces.

#12 follow-up: @johnstonphilip
11 years ago

Unfortunately, my computer had a complete meltdown while I was trying to update to the latest WP version and then create the new patch - due to me using the wrong commands I think. Took me several days to get it back in working condition so I doubt I'll ever get the courage to try another patch again :(

Thanks for all your help Drew.

#13 in reply to: ↑ 12 @DrewAPicture
11 years ago

Replying to johnstonphilip:

Unfortunately, my computer had a complete meltdown while I was trying to update to the latest WP version and then create the new patch - due to me using the wrong commands I think. Took me several days to get it back in working condition so I doubt I'll ever get the courage to try another patch again :(

Thanks for all your help Drew.

Sorry to hear that. If you decide you'd like to give it another shot, feel free to ping me in #wordpress-sfd (IRC) or here and I'll give you a hand.

@johnstonphilip
10 years ago

This adds a filter hook for the default page template's title in WordPress.

#14 @johnstonphilip
10 years ago

  • Keywords has-patch added; needs-patch removed

I mustered up the courage to take another shot at this :)

#15 @SergeyBiryukov
10 years ago

  • Milestone changed from Awaiting Review to 4.1

#16 @johnbillion
10 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 30360:

Add a filter to the displayed title of the default page template.

Fixes #27178
Props johnstonphilip

#17 @johnbillion
10 years ago

I tidied up the patch a bit and added some late escaping.

Note: See TracTickets for help on using tickets.