Stop hyperlinking images!

Norcross Dec 19th, 2011functions file

This has always been a pet peeve of mine. By default, WordPress will set the link to any image that you upload to the file itself. That’s great if you’re using some sort of LightBox setup, but 99% of the time you aren’t. It’s just the image. So if you forget to remove the link… dice.

Well, not if you add this handy line to your functions file

update_option('image_default_link_type', 'none');

Yep, that’s it.

** UPDATE 12/21/2011 **

Thanks to @mitcho for pointing out that we don’t need the option to update every time, only once. So here’s a slightly modified function to check the value first, then update if it isn’t set to ‘none’.

** UPDATE 06/19/2012 **

Seems that the release of WP 3.4 changed how the function operated (slightly). Take a look at the updated function below.

35 Responses to “Stop hyperlinking images!”

  1. mitcho

    If this is an option, there’s no need for the update_option to be run on every page load, though, right?

    • Norcross

      Good point. I’ve updated the post to have it check the option value first, then only update if it isn’t ‘none’.

  2. Matt Wiebe

    If you don’t want to actually set the option, you can just use a filter override to ensure it will never change back:

    add_action('pre_option_image_default_link_type', 'always_link_images_to_none');
    function always_link_images_to_none() {
    return 'none';

    • alex chousmith

      was a little worried all this talk of WP 3.4 would mean the solutions might not work in 3.5(.1) , but matt wiebe’s filter approach works like a champ. thx guys!

  3. Jupiter Jim

    I am sorry, I have tried both the modified code and the code using the filter by Matt Weibe. I’ve tried them both on my real site and my demo site. I click on images added by pasting the URL “the Thesis Way” and clicked on images that are just uploaded to the post.

    I can tell you that sometimes it works and sometimes it doesn’t, even on the same site with different pics.

    Very strange.

    Anyone else with this problem?

    BTW, I love this font. may I ask what it is?


    ~ Jupiter Jim

    • Norcross

      Keep in mind this won’t affect any images that have already been posted, only those going forward. Also, this won’t affect anything using custom fields (Thesis or otherwise), but it should remove the default ‘link’ option when using the media uploader.

      And the font is the Century Gothic font stack.

  4. Luke Shield

    Odd, this doesn’t seem to work on WordPress 3.4
    It looks like they’ve changed the structure of the options.php file?

    • Norcross

      I hadn’t looked closely at how this would work in 3.4. Let me see what’s up and I’ll update the tutorial accordingly.

  5. Mo


    Thanks for the tip Norcross.
    Have you been able to make it works on WP3.4 ?
    For me it doesn’t work, tried the updated one 19 of june.

    Thanks for your feedback 😉

    • Norcross

      I just checked again, and the updated function works. Keep in mind that this won’t affect any images already in posts, rather, only the actual media uploader process of adding the link. If your theme has some sort of auto-linking function, this wouldn’t change that.

      • Mo

        Hi Nocross,

        Thanks for the quick reply 😉 I was also suspecting a theme issue, because haven’t found anyone complaining about this tip nor the others using the hidden options page 🙂
        I’m using the minimalist “core” theme with images scroll on hompage and wanted to use images as Websites bookmarks, therefore would like to change image url to website link. Any Help Will be greatly appreciated … 😉

        • Norcross

          That would involve modifying the theme code itself. I have no clue how that theme itself is built. If you’d like to hire me to troubleshoot it, you can contact me using the contact form on my business website here

          • Mo

            Thanks for the proposition, but I’m not sure it’s related to the theme. Yesterday I tried again with version 3.3 and the default theme (20/11), and and tried all the tips and I wasn’t able to to see that field editable at all. I really don’t know what’s wrong, could be something with OVH or the DB or file access rights…. I also checked the DB and the image type setting is clearly shown ‘none’.
            I will continue my research and then maybe will contact for a private support. Thanks a million for sharing your knowledge and experiences 😉

  6. Dietrich

    I updated option image_default_link_type to file. The url will be shown correctly, the link is changed to image file, but in the gallery setting attachment page stays activated and if I go to front end the thumbnail ist linked to the attachment file and not to the image. In wp_options database image_default_link_type is set do file.
    What is wrong?

  7. Andrew

    Isn’t it quicker to simply set it every time rather than check if it’s set and then set if not?

    • Norcross

      It’s really 6 one, half dozen the other. Running the check avoids an actual database write.

  8. Aditya Pandey

    Thanks you very much.

    I just don’t know why WordPress have attachment page option, it really annoys me at least.
    Some kind of plugin triggered to post image as attachment by default.
    I solved it by using your function, changing “none” to “file”.

    Thanks again. 🙂

  9. Roezer

    Works on the Origin Theme thanks, I found it annoying that Images would link to the file url good for scrapers and hotlinkers but not the rest of us is how I think of it.

  10. Tony

    Just started having problems adding a link to images in my posts. Anyone else having the same problem?

    • Norcross

      yep. this function does basically the same thing. but it also runs the check so it doesn’t switch back.

  11. Michael

    sorry, it does not work.. I added the line to options.php but when I upload an image it is still linked to itself or to a media page… -.- I have to add 1000 pictures and I have always to remove the link, it is a pain in the ass 🙁

    • Norcross

      Do you mean your functions.php file? not sure what that options would be, other than something custom to your theme.

      However, I’ve used this on a 3.6 install without any issue.