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.

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.

enter image description here

Is there a solution to hook into the "media-upload" "pop-in" ?

Thanks by advance.

share|improve this question
    
What theme do you use? –  kaiser May 23 '11 at 21:44
    
I use a custom theme that I created. –  inwpitrust May 28 '11 at 10:28
add comment

6 Answers 6

up vote 6 down vote accepted

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 );
share|improve this answer
add comment

Go to-> http://yourblog.com/wp-admin/options.php Search for: image_default_link_type Type: none

share|improve this answer
    
This is great, i'm sure most people don't know of this image_default_link_type setting –  jasondavis May 23 '13 at 3:11
    
this is core files. best to avoid editing those. update_option('image_default_link_type','none'); in functions.php will do the trick –  honk31 Jun 15 at 18:50
add comment

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

share|improve this answer
add comment

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" title="%2$s">%3$s &times; %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.

share|improve this answer
    
I use a custom theme which doesn't have loop-attachment.php in it. –  inwpitrust May 28 '11 at 10:31
    
ok. that complicates things. if you want to go down this route I would suggest you look in the main loop of the twenty-ten theme and see where the loop-attachment.php fits in, and try and import it over. Otherwise you could look for instances of wp_get_attachment_metadata() in your theme to see where your theme is attaching the image links. –  edzillion May 28 '11 at 11:56
add comment

In functions.php or likewise file:

  update_option('image_default_link_type','none');
share|improve this answer
add comment

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\/(.*?)"/i', '<a$1href="$2"', $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.

share|improve this answer
    
Hi, thanks for the response but it doesn't seem to work. I also updated my question because removing 'attachment/name-of-image-file' is not exactly what I need. –  inwpitrust May 28 '11 at 11:03
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.