I’m sure it’s happened to you. You’re checking out someone’s website. It looks good. Nice images. Oh, this one’s a link! I wonder where it goes? Oh. It’s the same picture I was just looking at, only now it’s the only thing on the damn page.
I don’t like it either, but it’s easy to understand why it happens. The option image_default_link_type can have three values.
- none (the image will have no link)
- file (the image will link back to the image file)
- post (the image will link to its associated post, page, or other post type)
The default value WordPress uses is “file”. The problem here is that every time you upload an image, you need to switch this to none. Sure, there’s a dropdown menu with all three choices on the same screen where you upload your media, but a lot of people either don’t know about it or don’t care that it pisses me off when images link to themselves.
Having said that, there is a simple solution. Change the default value. There are a few ways you can do this.
- Edit your wp_options database table. I know. There are hundreds, if not thousands, of rows in your table. How ever will you find it? Query the table.
SELECT * FROM `wp_options` WHERE `option_name` = 'image_default_link_type';
- Edit your options.php file. http://{your_wp_install}/wp-admin/options.php. This will display all your options, formatted and ready to edit. Just remember to hit Save Changes when you’re done!
- Edit your theme’s functions.php file.
function mac_imagelink_setup() { $image_set = get_option( 'image_default_link_type' ); if ($image_set !== 'none') { update_option('image_default_link_type', 'none'); } } add_action('admin_init', 'mac_imagelink_setup', 10);
- Create a plugin. Editing your theme’s functions.php will only work as long as you don’t switch themes. This is why I suggest building a plugin using the above code. That way, the solution becomes “theme-agnostic”.