Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Actualy the question says it all. I integrated a media upload box to my admin page and a button with the text 'Insert into post' makes no sense. I rather like to change it to something like 'Use this image'. Anyone got a clue on how you are able to do so?

share|improve this question
add comment

4 Answers

up vote 3 down vote accepted
add_filter("attribute_escape", "myfunction", 10, 2);
function myfunction($safe_text, $text) {
    return str_replace("Insert into Post", "Use this image", $text);
}

Place in your theme functions file of in a plugin file.

The first usable filter that this button hits is on the function esc_attr(). So what that code will do is find any instance of Insert into Post that is run through esc_attr() and replace it to Use this image. This code might have undesired issues elsewhere though. Maybe there is a language file method someone might know of that might be a better solution than this.

TRY:

add_filter("attribute_escape", "myfunction", 10, 2);
function myfunction($safe_text, $text) {
    return str_replace(__('Insert into Post'), __('Use this image'), $text);
}

Should account for translations.

share|improve this answer
    
I put this in my plugin, however when the media uploader is triggered by a button it will still show 'Insert into post' =/ –  Mark Feb 9 '12 at 16:46
    
Insert into post or Insert into Post notice the difference –  Brady Feb 9 '12 at 16:51
    
Ah I discovered the flaw. I have a dutch version of WordPress, in the attribute_escape the sentence is already translated so it could not find the Insert into post string. –  Mark Feb 9 '12 at 16:57
    
@Mark have a look at my update –  Brady Feb 9 '12 at 17:00
    
Then one last question. It's logic that it will also change the text on the media box of the post and page where Insert into Post does make sense how can I avoid that from happening? –  Mark Feb 9 '12 at 17:05
show 1 more comment

Filter 'gettext', take care to catch the target string only by checking the text domain. See this answer for a rather verbose example.

A simplified way:

add_filter( 'gettext', 'wpse_41767_change_image_button', 10, 3 );

function wpse_41767_change_image_button( $translation, $text, $domain )
{
    if ( 'default' == $domain and 'Insert into Post' == $text )
    {
        // Once is enough.
        remove_filter( 'gettext', 'wpse_41767_change_image_button' );
        return 'Use this image';
    }
    return $translation;
}

This is the only way to avoid false positives. A plugin author may use the same string in another location, so you have to verify the text domain.

share|improve this answer
add comment

WARNING: using the hook "attribute_escape" is kinda bad. This function is called for ALL text including post titles and content. Using this filter as stated in the accepted answer breaks html entity encoding.

For instance the title Features & Pricing appears as Features & Pricing in the title field. After saving it then shows Features & Pricing. After saving again you get Features & Pricing.

A better alternative might be to use jquery to change the button text.

add_action( 'admin_head', 'admin_head_script' );
function admin_head_script()
{
?>
<script>
    jQuery(document).ready(function($){
        $('input[value="Insert into Post"]').val('Use this Image');
    });
</script>
<?php
}
share|improve this answer
add comment

With WordPress 3.5+ Media Uploader, there's another way. All strings are localized at the bottom of the page with:

<script type='text/javascript'>
/* <![CDATA[ */
var _wpMediaViewsL10n = {
    "url":"URL",
    "addMedia":"Add Media",
    "search":"Search",
    "select":"Select",
    "cancel":"Cancel",
    "selected":"%d selected",
    "dragInfo":"Drag and drop to reorder images.",
    "uploadFilesTitle":"Upload Files",
    "uploadImagesTitle":"Upload Images",
    "mediaLibraryTitle":"Media Library",
    "insertMediaTitle":"Insert Media",
    "createNewGallery":"Create a new gallery",
    "returnToLibrary":"\u2190 Return to library",
    "allMediaItems":"All media items",
    "noItemsFound":"No items found.",
    "insertIntoPost":"Insert into post",
    "uploadedToThisPost":"Uploaded to this post",
    // ET CETERA
    };
/* ]]> */
</script>

On document.ready, we modify the object:

add_action('admin_footer', function()
{
    ?>
    <script type="text/javascript">
        // or without jQuery: http://stackoverflow.com/q/799981
        jQuery(document).ready( function($) {
            _wpMediaViewsL10n.insertIntoPost = 'Gotchya!';
        });
    </script>
    <?php
});
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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