Automatically Link Image Blocks to Their Media File
By default, WordPress does not link inserted images to their media file. For image-heavy websites such as portfolios or sites using lightbox functionality, this often creates unnecessary manual work.
Use a snippets plugin like WPCodeBox to keep the setting independent of your theme, that way it won’t disappear if you switch or update themes. Alternatively, you can place the code directly in your theme’s functions.php file.
After saving and activating it, any new Image Block you insert will automatically have the link type set to your selected default.
PHP
<?php
add_action('after_setup_theme', function () {
/*
* Sets the default link behavior for images inserted via the media uploader.
*
* Available options:
* 'file' - Links the image directly to the media file URL
* 'attachment' - Links the image to its WordPress attachment page
* 'none' - Inserts the image with no link wrapper
*/
update_option('image_default_link_type', 'file');
});


No Comment! Be the first one.