#27178 closed enhancement (fixed)
Filter Hook for "Default Template"
Reported by: | johnstonphilip | Owned by: | 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)
Change History (20)
#3
@
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 );
#5
@
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
@
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
@
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
@
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.
#11
@
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:
↓ 13
@
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
@
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.
#14
@
10 years ago
- Keywords has-patch added; needs-patch removed
I mustered up the courage to take another shot at this :)
There was an error in my replacement code. Should actually read as: