• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Notes to Self

  • Aviation Weather from NOAA Plugin
    • KZZV
    • Bad Shortcode
    • Simple Metar
  • Meetings

Mark Chouinard / June 1, 2013

WordPress Images Linking to Themselves

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

Filed Under: WordPress

Primary Sidebar

Post Archives

  • June 2024
  • December 2022
  • July 2022
  • December 2021
  • October 2021
  • June 2021
  • February 2021
  • October 2020
  • September 2020
  • August 2020
  • March 2020
  • February 2020
  • December 2019
  • September 2019
  • June 2017
  • May 2016
  • April 2016
  • March 2016
  • September 2015
  • August 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • June 2013
  • May 2013
  • April 2013
  • February 2013
  • January 2013
  • December 2012
  • January 2011

Footer

Copyright © 2025 · machouinard · Log in