WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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 '12 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 '12 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 '12 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 '12 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 '12 at 16:45
up vote 5 down vote accepted

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;
share|improve this answer
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 '12 at 2:47
A workaround is to use the filter media_send_to_editor and do a strip_tags($html,'<img>'); – brasofilo Dec 28 '12 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 '12 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 '12 at 14:09
Which drop down, do you have a hint, Screenshot for me? – bueltge Dec 29 '12 at 22:06

Your Answer


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.