I am trying to change the "Set featured image", "Remove featured image", and "Use as featured image" text links of a custom post type for my plugin Meteor Slides.
I found the "admin_post_thumbnail_html" filter hook, and came up with some code that will change "Set featured image" to "Set slide image" for just the slide post type:
if ((isset($_GET['post_type']) && $_GET['post_type'] == 'slide') || (isset($post_type) && $post_type == 'slide')) {
add_filter( 'admin_post_thumbnail_html', 'meteorslides_set_featured', 9999, 1 );
function meteorslides_set_featured( $content ) {
return str_replace( 'Set featured image', 'Set slide image', $content );
}
}
I tried the same thing for "Remove featured image" and it did not work, however I can use this code to make this change for all post types:
add_filter( 'admin_post_thumbnail_html', 'meteorslides_remove_featured', 9999, 1 );
function meteorslides_remove_featured( $content ) {
return str_replace( 'Remove featured image', 'Remove slide image', $content );
}
Does anyone have any thoughts as to why filtering "Set featured image" would behave differently than "Remove featured image"?
Changing "Use as featured image" seems to be a bit trickier, there isn't a filter for this. But I did find a ticket in Trac where someone else was trying to do the same thing, and there was a suggestion to filter the translation string.
This solution worked pretty well, I was able to change the "Use as featured image" text, but again it is for all post types and I'm not sure how to narrow it down:
add_filter( 'gettext', 'meteorslides_use_featured', 9999, 4 );
function meteorslides_use_featured( $translation, $text, $domain ) {
$translations = &get_translations_for_domain( $domain );
if ( $text == 'Use as featured image' ) {
return $translations->translate( 'Use as slide image' );
}
return $translation;
}
The overlaid media window doesn't seem to "know" that I am loading it from a certain post type, so I'm not sure if this change is doable.
I did find an answer on here that showed how to change these links with jQuery. I'd prefer to use filters, but if I could figure out how to limit that to one post type that'd be alright too!
I've been looking around at some other plugins that use featured images but I haven't been able to find any that have changed all of these strings. Has anyone pulled this off?
$typenow
var and see if that's set.. It's all just a matter of working with the hooks available, and i'm not sure there's one specifically for that piece of text(aside from the gettext one)..