WordPress.org

Support

Support » Requests and Feedback » Why are images linked by default?

Why are images linked by default?

  • 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.

Viewing 15 replies - 1 through 15 (of 18 total)
  • This is driving me insane. Am I the only person who thinks this is a problem?

    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…

    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:

    $('a[rel="colorbox"]').colorbox();

    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!

    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');

    Nice one Zeo, thanks.

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

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

    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 🙂

    IMO? NEVER EDIT CORE!

    how exactly do I set it from options.php?

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

    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?

    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

    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.

    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.

    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’ ?

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Why are images linked by default?’ is closed to new replies.
Skip to toolbar