1

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?

2 Answers 2

2

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;
}
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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