Stop hyperlinking images!

A pet peeve of mine, if you will. 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…..no 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’.


$image_set = get_option( 'image_default_link_type' );
	if (!$image_set == 'none') {
		update_option('image_default_link_type', 'none');
	}

{ 10 comments… read them below or add one }

saracannon December 19, 2011 at 11:00 pm

YES. thank you :)

Reply

mitcho December 21, 2011 at 3:01 pm

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

Reply

Norcross December 21, 2011 at 3:13 pm

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

Reply

Avinash D'Souza December 21, 2011 at 3:55 pm

Andrew, would this work in Thesis too?

Reply

Norcross December 21, 2011 at 10:34 pm

yep. framework agnostic.

Reply

Brett Deaton December 22, 2011 at 10:58 am

This is the best post of the week! Thank you!

Reply

Josh Hartman December 22, 2011 at 11:21 am

This was useful, thanks Andrew!

Reply

Matt Wiebe December 22, 2011 at 11:32 am

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

Reply

Norcross December 23, 2011 at 6:39 am

hadn’t considered the filter route. thanks!

Reply

Susan January 3, 2012 at 1:20 pm

Sweet, thanks for that tip!

Reply

Leave a Comment

Previous post: