7

How do I remove the Insert from URL link in the new Wordpress 3.5 Add Media popup page? In earlier versions of Wordpress, this worked fine:

// removes URL tab in image upload for post
function remove_media_library_tab($tabs) { 
    if (isset($_REQUEST['post_id'])) {
        $post_type = get_post_type($_REQUEST['post_id']);
        if ('premium' == $post_type)
            unset($tabs['library']);
            unset($tabs['type_url']);
    }
    return $tabs;
}
add_filter('media_upload_tabs', 'remove_media_library_tab');

Who knows?

2 Answers 2

6

This should work:

add_filter( 'media_view_strings', 'cor_media_view_strings' );
/**
 * Removes the media 'From URL' string.
 *
 * @see wp-includes|media.php
 */
function cor_media_view_strings( $strings ) {
    unset( $strings['insertFromUrlTitle'] );
    return $strings;
}
2
  • Works great - well done!
    – Christine Cooper
    Dec 16, 2012 at 17:16
  • Is this possible to be done via javascript, I used the media manager in post metabox, so I can't do this via filter since it will ruin the post 'add media' behaviour.
    – ayublin
    Jan 20, 2013 at 15:16
3

The code of default tabs array in new WP is in media.php and looks like this:

/**
 * Defines the default media upload tabs
 *
 * @since 2.5.0
 *
 * @return array default tabs
 */
function media_upload_tabs() {
    $_default_tabs = array(
        'type' => __('From Computer'), // handler action suffix => tab text
        'type_url' => __('From URL'),
        'gallery' => __('Gallery'),
        'library' => __('Media Library')
    );

    return apply_filters('media_upload_tabs', $_default_tabs);
}

If you want only remove upload from url by default you shoud change your function to:

// removes URL tab in image upload for post
function remove_media_library_tab($tabs) { 
    unset($tabs['type_url']);
    return $tabs;
}
add_filter('media_upload_tabs', 'remove_media_library_tab');

Not tested but it should work fine.

Edit: Not work because this array is used in other place. If you want just remove the link you can use this work around:

function remove_media_library_tab(){
    ?>
    <style>
        .media-menu a:last-child{ display:none}
    </style>
    <?php
}
add_action('admin_head', 'remove_media_library_tab');
4
  • This does not work I'm afraid. Maybe you could try it yourself and debug the code...?
    – Christine Cooper
    Dec 15, 2012 at 18:12
  • 1
    I edit my answer, you can check new code (works in my WP) or just copy css rule to your style.css. I can't find method to remove this option from php. Dec 15, 2012 at 18:45
  • Cor van Noorloos answer works better as it unsets it rather than hiding it through CSS. However, this was a good approach which is why I have upvoted it.
    – Christine Cooper
    Dec 16, 2012 at 17:17
  • Yep, it's better ;) I just check it - it use a new filter from WP 3.5 which I did not know ;) Dec 16, 2012 at 17:22

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.