Changing The Default WordPress Attachment Link

WordPress is the best Content Management System and is used by many. But everything has some pros and cons and WordPress is no exception. One of the problem I faced using the CMS was the link from any media file I upload, always pointed to the attachment page by default. I always had to change it to none while attaching the file. This was a tedious task and then I found a workaround to change the default WordPress attachment link.

Changing The Default WordPress Attachment Link

There are two ways to do it, one is temporary and you will have to redo it once you upgrade or reinstall WordPress but is quite easy to do. The other method is permanent but you need to edit your functions.php file in your current theme’s folder.

Changing Media Link URL by altering options.php :

Wordpress displays all the settings on a single page which is located at “http://www.example.com/wp-admin/options.php” where example.com needs to be replaced by your domain name.
  1. Go to the URL by changing example.com with your domain name.
  2. Now all the options are arranged in alphabetical order, scroll down until you find “image_default_link_type”. You can also search if you feel like.
  3. The input box on the right side can hold three different values.
    1. post – Which points to the attachment page.
    2. file – It points directly to the URL of your attachment
    3. none – It gives no link to your attachment.
  4. Press the “Save Changes” button at the bottom of the page.
Depending on the above options you can easily change the default WordPress attachment link.

Changing Media Link URL by altering functions.php File :

  1. Open your WordPress admin panel and navigate to Appearance > Editor.
  2. Now from the right pane find “functions.php” file and at the very last (before closing php tag) paste the following code.

    function mytheme_setup() { update_option(‘image_default_link_type’, ‘post‘ ); } add_action(‘after_setup_theme’, ‘mytheme_setup’);

    The “post” here again can be anything from file, post or none.

  3. Now save the changes you have made.
Verdict
Now you have finally changed the default WordPress attachment link according to your needs.
Related Post