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.

How can I get rid of the attachment URLs completely?

I don't want users to have the ability to link an image to the Attachment URL when inserting an image, ever.

I've done things in the past like redirect back to the attachment's parent ID and could even alter it to redirect to the full size file URL but I'd rather get rid of having a permalink for attachments all together.

Does anyone know of a way to disable this via the functions.php file?

share|improve this question
add comment

2 Answers

The form for the 'From Url' tab seems to be pretty much hard-coded, so I don't think there is away of removing the 'Link Image To' field.

However, for the Media Library tab you can remove the link field, with the following:

add_filter('attachment_fields_to_edit', 'my_attachment_fields_edit', 10, 2);
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;
}
share|improve this answer
add comment

Are you asking for images that you insert into the post WYSIWYG editor to not have attachment links? Because when you insert an image into a post you have the option of wrapping it in a link or having no link. Is this what you mean?

In the image attached below, you'll see the link URL box, click the button that says none every time you insert an image. This will work manually, but the code above from Stephen will work if you want this to be automatic.

enter image description here

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.