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.- Go to the URL by changing example.com with your domain name.
- 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.
- The input box on the right side can hold three different values.
- post – Which points to the attachment page.
- file – It points directly to the URL of your attachment
- none – It gives no link to your attachment.
- Press the “Save Changes” button at the bottom of the page.
Changing Media Link URL by altering functions.php File :
- Open your WordPress admin panel and navigate to Appearance > Editor.
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.
- Now save the changes you have made.
Verdict
Now you have finally changed the default WordPress attachment link according to your needs.