Why are images linked by default? (19 posts)

  1. nickaster
    Posted 5 years ago #

    Since the latest update to wordpress, images are automatically made into hyperlinks, hilariously to themselves.

    I can see how this would be useful if you were using thumbnails and linking to a big version, but 99% of the time, this just adds useless code and confuses visitors who click on the images by accident.

    I also know that once you uncheck the box then it won't happen again, but amateur bloggers are now making posts everywhere with these annoying links in them. Plus, if you run a big blog, it's one more thing you have to explain to people who don't understand HTML to avoid.

    Can we please make UNLINKED images the default in the next revision?

    Just my two cents.

  2. nickaster
    Posted 5 years ago #

    This is driving me insane. Am I the only person who thinks this is a problem?

  3. Richard Sweeney
    Posted 5 years ago #

    I agree. Seems totally daft.

    The hyperlinks aren't even given a class by default so my idea to put the linked image in a modal dialogue doesn't even work!

    Gotta be a workaround for this somewhere...

  4. Richard Sweeney
    Posted 5 years ago #

    Found quite a nice solution to open the linked images in a modal dialogue - I use colorbox as it's easily the best (jQuery modal dialogue) and very easy to customize.

    I added the following to functions.php:

    add_filter('the_content', 'addColorbox');
    		function addColorbox ($content) {
    			global $post;
    				$pattern = "/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
    		  	$replacement = '<a$1href=$2$3.$4$5 rel="colorbox"$6>';
    		    $content = preg_replace($pattern, $replacement, $content);
    				$content = str_replace($pattern, $post->ID, $content);
    		    return $content;

    Which adds a rel="colorbox" to hyperlinked images.

    Obviously you have to link to jQuery and colorbox in the <head> section of your page, but the following simple call will sort you out:


    Colorbox - and WordPress of course - both allow you to specify a max width / height to stop the linked image taking over the entire screen!

    Of course you could use any modal dialogue - there's even a plugin that will let you do this without getting your hands dirty!

  5. Safirul Alredha
    Posted 5 years ago #

    Run this in theme's functions.php or plugin file. This will set the default for any future usage. Choose one:

    None: update_option('image_default_link_type' , '');
    File URL (this is WordPress default): update_option('image_default_link_type' , 'file');
    Post URL: update_option('image_default_link_type' , 'post');

  6. Richard Sweeney
    Posted 5 years ago #

    Nice one Zeo, thanks.

  7. Safirul Alredha
    Posted 5 years ago #

    Optionally, browse to http://yourblog.com/wp-admin/options.php and find image_default_link_type. You can also set from there.

  8. nickaster
    Posted 5 years ago #

    Very cool. Thanks Zeo. I'm kinda scared to mess with functions. Will this mess up future upgrades to wordpress?

  9. If you put it in your functions.php file, in your theme, then NO, upgrades won't affect it unless the function you change is deprecated. Which in this case? Highly unlikely :)


  10. Kyle Jennings
    Posted 5 years ago #

    how exactly do I set it from options.php?

  11. Barryisgod
    Posted 5 years ago #

    it"s difficult for me to understand since i haved used English for too long .

  12. nickaster
    Posted 5 years ago #

    OK.... so I did this and new authors are apparantly still getting the link by default. Is it possible something is wrong with that code? What's the exact way to include it?

    update_option('image_default_link_type' , '');

    Like, do i just past that exactly in there? Isn't there supposed to be some <?php something or other around it?

  13. nickaster
    Posted 5 years ago #

    Hey, anyone got an obvious solution other than the one above? I added that line to options.php and no luck, new users still are doing the dang link by default

  14. Chris Bratlien
    Posted 5 years ago #

    I'm pretty sure Zeo didn't mean for you to actually edit the options.php file. I think you should undo the lines you edited there.

    Did you try Zeo's 2nd suggestion of browsing to http://yourblog.com/wp-admin/options.php while you're already logged in to the Dashboard?

    You should see a huge list of settings, and when you find that setting for image_default_link_type, it's probably set to 'file', which you want to clear out and then click Save at the bottom of all of the options.

  15. nickaster
    Posted 5 years ago #

    woah. I had NO idea that page existed. Thanks!

    So, curiously, it is in fact blank. I will have to double check this, as what I actually edited was functions.php, not options, so maybe this was already 'fixed', but I swear new users are still getting the stupid link in there. I'll have to do an experiment. Stand by.

  16. Chris Bratlien
    Posted 5 years ago #

    When you edited functions.php, that line of code did blank out that option. What happens when you change tbat option from blank to 'post' ?

  17. miniCarl
    Posted 5 years ago #

    Here's your solution nickaster!

    1) You don't need that code in functions.php
    2) Yes, make sure image_default_link_type is blank in /options.php

    BUT, here is what you've all missed
    Link settings are also saved individually for each image.
    You need to delete your images not only from your posts/pages but also from your media library, and upload them again. There you go, no default links anymore.


  18. Roy
    Posted 5 years ago #

    Never knew that WP has a 'God mode'. Thanks for the tip!

  19. billzy
    Posted 4 years ago #

    @Zeo, Im months late on this post.. but you are a LEGEND... why did it take weeks of searching on and off to find this page... Should be in the official wp documentation... ty for sharing!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.