In the Media upload popup page, how do I set the attachment link to none and hide it in Wordpress version 3.5? The following filter worked fine in earlier versions of WP:

function my_attachment_fields_edit($form_fields,$post){ 
    // Set attachment link to none and hide it.
    $html = "<input type='hidden' name='attachments[".$post->ID."][url]' value=''/>";

    $form_fields['url']['html'] = $html; //Replace html
    $form_fields['url']['label'] = ''; //Remove label
    $form_fields['url']['helps'] ='';//Remove help text

    return $form_fields;
add_filter('attachment_fields_to_edit', 'my_attachment_fields_edit', 10, 2);

This was actually an excellent filter posted by someone here I believe. Do anyone know how to accomplish this in WP 3.5?

  • This isn't really a solution more of a bump as I am struggling with this as well. I have done some digging in the core files to see if I could find an action or filter we could hook into but it appears that this area is hard coded. (See /wp-includes/media-template.php) I might be wrong but any solution might involve some JavaScript to work around this. Its really strange that all the options around the link option have various hooks and filters yet the link option doesn't have any. I will keep digging for a solution.
    – user25015
    Dec 19, 2012 at 13:19
  • I understand that you do not have the ability to post a comment to this and thus you added an answer. Please keep me informed if you do find an answer. In my personal opinion, an option to set the attachment to none should be a part of the core Wordpress preferences.
    – Christine Cooper
    Dec 19, 2012 at 22:52
  • Yes sorry - I don't have the ability to post a comment yes. I have gotten a little bit further, after speaking to the WP Lead Developer he has confirmed that it is now hard coded to there is no hook we could use any more. He did however point out that it saves the users last uses setting in the database and then uses this as the default. Although not an ideal solution I am looking at writing a hook that sets all the users link preference to point to the 'Media File' by default.
    – user25015
    Dec 20, 2012 at 10:14
  • Thank you for sharing this information. If you find a way how to add a hook that sets all users preferences to None then please post it. Maybe it does a check on every page load? And maybe we can do a good old display:none in the stylesheet for that dropdown list...
    – Christine Cooper
    Dec 20, 2012 at 14:35
  • The data is stored in the wp_usermeta table in the record: wp_user-settings. The urlbutton is the option you need to set to None.
    – user25015
    Dec 20, 2012 at 16:45

2 Answers 2


Include this small plugin, activate and test.

A tested version in 3.6-alpha, works only on click on a thumbnail.

 * Plugin Name: Remove Attachment Link-To and set to value 'none' 

add_action( 'admin_footer-post-new.php', 'wpse_76214_script' );
add_action( 'admin_footer-post.php', 'wpse_76214_script' );
function wpse_76214_script() {
    <script type="text/javascript">
    jQuery(document).ready( function($) {
        $( 'li.attachment' ).live( 'click', function( event ) {
            $( ".link-to > [value='none']").attr( "selected", true ); // selected none in select field
            $( ".link-to-custom" ).val( '' ); // clear input field for target of link
            $( '.media-sidebar div.setting' ).remove(); // remove link field
    } );

// filter a-Tag in data, there was send to edit; fallback
add_filter( 'media_send_to_editor', 'wpse_76214_send_to_editor', 10, 3 );
function wpse_76214_send_to_editor( $html, $id, $attachment ) {

    $html = preg_replace( '@\<a([^>]*)>(.*?)\<\/a>@i', '$2', $html );

    return $html;
  • 1
    Aha, finally we are getting into that screen, cool! ::: Running 3.5: it works to select "none" and to remove the dropdown, but the image is inserted with the link. It is like attr("selected", true) is just "cosmetic", visually it changes, but in practice WP doesn't gets it...
    – brasofilo
    Dec 28, 2012 at 2:47
  • 1
    A workaround is to use the filter media_send_to_editor and do a strip_tags($html,'<img>');
    – brasofilo
    Dec 28, 2012 at 2:56
  • I have tested now, and it works always fine, send without linkfield, if the user dont change the value of this selec field. But now I have add in the source a line to clear the target field and without a value in this field was not insert a a-Tag in the editor. Maybe this helps.
    – bueltge
    Dec 28, 2012 at 8:20
  • @bueltge Works great, very well done! However one final problem remains. The attachment drop down option is still visible in the media uploader. Is there any way to hide it?
    – Christine Cooper
    Dec 29, 2012 at 14:09
  • Which drop down, do you have a hint, Screenshot for me?
    – bueltge
    Dec 29, 2012 at 22:06

A dirty way is to catch any time anyone clicks anywhere and hide the div that contains the "ATTACHMENT DISPLAY SETTINGS". Assuming you have jQuery:

$(window).click(function() {

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.