4

I don't want to edit core files in order to change the page where a user enters new posts, so is there a way to do it within a theme, perhaps within functions.php ..?

Specifically, I'm trying to change the wording of the 'Set featured image' text to something like 'Set featured image - 50 pixels by 50 pixels'

3
  • 1
    I'd just use jQuery. Commented Sep 9, 2010 at 13:56
  • I agree with John Bloch. Edit your functions.php of your theme to load an action event hook. This would need to detect one is in the admin mode. Then, once in admin mode, make it load jQuery and then make it activate your jQuery snippet.
    – Volomike
    Commented Sep 10, 2010 at 5:24
  • I'm using a modification of this in a plugin and I'm running into difficulties (see here). Have you modified this for 3.0 successfully? Or do you have any thoughts as to what I need to do to make it work?
    – Evertiro
    Commented Sep 10, 2012 at 17:13

3 Answers 3

11

You can use the filter admin_post_thumbnail_html:

function custom_admin_post_thumbnail_html( $content ) {
    return $content = str_replace( __( 'Set featured image' ), __( 'Set featured image - 50 pixels by 50 pixels' ), $content );
}

add_filter( 'admin_post_thumbnail_html', 'custom_admin_post_thumbnail_html' );
5

One way is to use careful jQuery code inserted in the header of the admin to modify the text within a specific part of the page. You need to be able to target a specific div/span/html tag in order to do so, but this system will let you edit any part of the page even if there is no filter (though the answer by Sorich has a great filter for the use-case in your question, my answer applies more generally to your question itself).

I used the code below to alter the featured image box in 2.9 to say 'featured image' instead of 'post thumbnail' because the labels changed in 3.0 and I wanted my old site to use the new terminology before upgrading it.

Note that the code handles both the popup box and the metabox, and uses some jquery AJAX functions to ensure the content gets re-modded after pageloads in the iframe.

/**
 * Use jQuery to add context to the Featured Image metabox on post editing pages
 * and to change the label to be Featured Image instead of Post thumbnail in WP 2.9 
 * before the label changed.
 *
 * See javascript for info on removing these as they become part of the AP API
 */
function gv_admin_featured_image_tweaks() {
    ?>
<script type="text/javascript">
    jQuery(document).ready(function($) {
        /**
         * TEMPORARY: SWITCH VARIOUS LABELS TO SHOW FEATURED IMAGE INSTEAD OF POST THUMBNAIL
         * REMOVE WHEN 3.0 COMES OUT AND THIS IS THE DEFAULT LABEL
         */
        $('#postimagediv h3 span').text('Featured Image');
        // Only change the set thumbnail text if its that, otherwise we end up replacing the img tag when it is set
        if ($('#postimagediv #set-post-thumbnail').text() == 'Set thumbnail') {
            $('#postimagediv #set-post-thumbnail').text('Choose Featured Image');
        }
        $('#postimagediv #remove-post-thumbnail').text('Remove Featured Image');

        // label inside media item details in popup
        $('.wp-post-thumbnail').text('Use as Featured Image');
        // refresh inside media item for after upload finishes.
        $('body').ajaxComplete(function() {
            $('.wp-post-thumbnail').text('Use as Featured Image');
        });

        /**
         * Add a description of how we use featured images. should be replaced with a description parameter in the API
         */
        $('#postimagediv .inside').prepend('<p>This image will be used in the featured posts slider if this post is featured. It should be at least 400px wide by 300px tall.</p>');
    });
</script>
    <?php
}
add_action('admin_head', 'gv_admin_featured_image_tweaks');
0

Easier solution here:

add_action( 'admin_head', 'replace_default_featured_image_meta_box', 100 );
function replace_default_featured_image_meta_box() {
    remove_meta_box( 'postimagediv', 'my-post-type-here', 'side' );
    add_meta_box('postimagediv', __('My Cover Image'), 'post_thumbnail_meta_box', 'my-post-type-here', 'side', 'high');
}

The main idea is: re-declaring the meta-box with the required title. Replace the post-type for which you want to edit the default "Featured Image" label.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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