How to Stop Auto Linking Images in WordPress

WordPress, by default, automatically links your image to the image file. While this may be desirable if you are using LightBox, there are some sites where you may never want to link to the image, simply because the image presented is already quite large or for other presentation reasons.

While it is true that you can manually turn this option off in the Media Library per image as you add each image in (or edit after the fact), in order to make life easier, you can just add a little code to your functions.php file to stop auto linking images in WordPress, and the link removal will be automatic for all image posts going forward.

You will still have the option to add in a link per selected images, if you choose; but nothing will be done automatically. Keep in mind that this technique will not affect any image posts made before you make this change; only image posts made after will follow the new rule.

As always, before you proceed with this fix, take a backup of your functions.php file using FileZilla or your preferred FTP application.

For those less familiar with the functions.php file (or PHP in general), remember to place this code before the closing statement ?>.

function wpb_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', 'wpb_imagelink_setup', 10);

To find your functions.php file, you can either use FileZilla (recommended) or the WordPress Dashboard (works in a pinch).

Using FileZilla

Connect to your webhost’s server using FileZilla. Navigate to the active theme for your site. This is found under wp-content>themes>yourthemefolderhere.

Double click to open the file, add the above code as described, and save your changes in a text editor. Next, upload the edited file back to the server.

Using the WordPress Dashboard

If you are using WordPress itself to access your functions.php file, the code and placement are the same. Just navigate to Appearance in the WordPress Dashboard. Look for Editor and click to enter the theme editor panel.

Once there, look for the functions.php file and click on it to open. Add the code as above and save your changes. Voila!

After You Make The Edit

Don’t forget to refresh your website from the front end (making sure to clear your cache) to verify that you didn’t break your functions.php file. For help clearing your cache, refer to this article from Wikipedia.

If your site shows and looks normal over a few pages, you are good to go. A problem in that area would typically result in your site’s front end not showing so be careful to tread lightly when touching key site files like this.

Now you are ready to go!

Submit a Comment

Your email address will not be published. Required fields are marked *

Pin It on Pinterest