I want to change the default “Excerpts are optional hand-crafted summaries of your content that can be used in your theme. Learn more about manual excerpts.” help text below the Excerpt input area to something more meaningful for my Custom Post Type.
I’ve done something similar with Post Title, using a “translation” filter, but how would I do this with the post excerpt?
Here is my current code:
add_filter('gettext', 'custom_rewrites', 10, 4);
function custom_rewrites($translation, $text, $domain) {
global $post;
$translations = &get_translations_for_domain($domain);
$translation_array = array();
switch ($post->post_type) {
case 'model':
$translation_array = array(
'Enter title here' => 'Enter model name here',
'Excerpt' => "Byline",
'Excerpts are optional hand-crafted summaries of your content that can be used in your theme.' => "Foobar"
);
break;
}
if (array_key_exists($text, $translation_array)) {
return $translations->translate($translation_array[$text]);
}
return $translation;
}
The third translation isn’t working?
This description is generated by
post_excerpt_meta_box()
function and is not passed through any explicit filters. It is however echoed by translation-related_e()
function and so passes throughgettext
filter (which from your question you are already familiar with).As for limiting it to your CPT, I think current post type in admin is held in global
$post_type
variable you can check.Late answer
Translation filters only
There’re default filters for the title and the content, but none for the excerpt windows. So you basically got to options: Remove the default meta box and add a new (altered) one OR filter the string via the
gettext
filter.Meta Box
You basically know the concept of removing a meta box (if not, just search on this very site for it). Then just add a new meta box that is exactly the same, but with a slightly altered UI in your custom callback.
Here’s the original from core as reference:
Gettext
The point with this is, that this filter triggers for each and every translatable string in the UI (which is a lot). In below plugin you’ll see how to alter the post types default title placeholder, the default content and how to hook in as late as possible to alter this string – and then im. remove the filter so it doesn’t slow down every later filter.
Thanks for this. It is also possible these days to apply a filter to the Title prompt using enter_title_here. Enjoy!
As you’d expect.