3

I want to change the wording in the Default thumbnail metabox to 'Set default thumbnail' instead of 'Set featured image'. How can I do this?

2

This is usually what I go with:

/** Use "Featured Image" Box As A Custom Box **/
function customposttype_image_box() {   
    remove_meta_box('postimagediv', 'page', 'side');
    add_meta_box('postimagediv', __('Set Dat Image'), 'post_thumbnail_meta_box', 'page', 'side');

}
add_action('do_meta_boxes', 'customposttype_image_box');

/** Change "Featured Image" box Link Text **/
function custom_admin_post_thumbnail_html( $content ) {
    global $post;
    if($post->post_type == 'page')
    {
        $content = str_replace( __( 'Set featured image' ), __( 'Upload dat Image' ), $content);
        $content = str_replace( __( 'Remove featured image' ), __( 'Remove dat image' ), $content);
    }

    return $content;
}
add_filter( 'admin_post_thumbnail_html', 'custom_admin_post_thumbnail_html' );
  • This is what I needed. I also needed to modify the text 'Remove featured image' if an image is already set. – urok93 Dec 3 '13 at 6:02
  • Also, what would happen if that string is translated into other languages? – urok93 Dec 3 '13 at 6:04
  • I updated my post to include a post_type conditional. The core problem with this is that it changes the text via javascript, so when you choose a featured image it changes the text right on the spot, same as when you remove it. My function will only work when the page is loaded. Maybe somebody else has a better workaround for this. – Howdy_McGee Dec 3 '13 at 15:01
  • Yes that's true, would love to know of a better workaround if anyone has it. – urok93 Dec 3 '13 at 19:15
  • @Howdy_McGee that is correct with JS issue. I think the only way to do this is via Javascript. – Anh Tran Dec 4 '13 at 2:02
1

Use media_view_strings to filter the default text.

Use the below in the active theme's function.php file

add_filter( 'media_view_strings', function( $strings ) {
   $strings['setFeaturedImageTitle'] = __( 'Set default thumbnail' );
   $strings['setFeaturedImage']    = __( 'Set default thumbnail' );

   return $strings;
});

Found in WordPress/wp-includes/media.php

  • This works for the lightbox image selection. What I want to edit however is the text in the postimagediv metabox, that's not changing with this code. – urok93 Dec 3 '13 at 5:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.