Is there a way to disable image attachment links trought a filter in functions.php or something ? I know it’s possible to do it manually when you add an image to a post but I want to disable this functionality by default.
UPDATE
What I want to do is set the “Link URL” option to “none” and remove / hide it from the upload attachement screen.

Is there a solution to hook into the “media-upload” “pop-in” ?
Thanks by advance.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If anybody is interested in do the trick, my solution is this:
function remove_media_link( $form_fields, $post ) {
unset( $form_fields['url'] );
return $form_fields;
}
add_filter( 'attachment_fields_to_edit', 'remove_media_link', 10, 2 );
Method 2
Go to-> http://yourblog.com/wp-admin/options.php
Search for: image_default_link_type
Change Value to: none (available options are none, file [links to the file itself], post [links to the post the image is related to], attachment [links to the attachment page with the image on it])
or set it in your functions.php via (same options available as mentioned above)
update_option( 'image_default_link_type', 'none' );
Method 3
There is a plugin to solve this called “Remove Link URL” and it removes the link by default, still allowing it to be added in if you click the button. I believe this fixes the problem you’re describing 🙂
screenshot-1.png?r=494378 http://img208.imageshack.us/img208/56/screenshot1vk.png
Method 4
I think you would have to edit the loop-attachment.php in your theme, specifically lines 50-61:
if ( wp_attachment_is_image() ) {
echo ' <span class="meta-sep">|</span> ';
$metadata = wp_get_attachment_metadata();
printf( __( 'Full size is %s pixels', 'twentyten' ),
sprintf( '<a href="%1$s" rel="nofollow noreferrer noopener" title="%2$s">%3$s × %4$s</a>',
wp_get_attachment_url(),
esc_attr( __( 'Link to full-size image', 'twentyten' ) ),
$metadata['width'],
$metadata['height']
)
);
}
Pretty sure commenting out this whole block will achieve what you want. Haven’t tested it myself though.
Method 5
In functions.php or likewise file:
update_option('image_default_link_type','none');
Method 6
Here is the basic php function that you would need to insert into your theme’s functions.php file:
<?php
function lose_attachment($content){
return preg_replace('/<a(.*?)href="(.*?)/attachment/(.*?)" rel="nofollow noreferrer noopener"/i', '<a$1href="$2" rel="nofollow noreferrer noopener"', $content);
}
add_filter('the_excerpt', 'lose_attachment',2);
?>
This will remove the ‘attachment/name-of-image-file’ part from the URL making it link to the post’s permalink itself.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0