How to add a default Media Link to your images in WordPress

It’s been bugging me ever since Gutenberg Blocks were introduced: how do I tell WordPress to always make my images clickable, so that readers can see a larger version by default? While I can set this manually, I have to do this for every image I post, which is ever so slightly mind numbing.

Thankfully there’s an easy solution as of WordPress 5.6, and it seems to work well from what I can tell after early testing. We’ll hook into the after_setup_theme hook and make it happen like this:

add_action( 'after_setup_theme', function() {
    update_option( 'image_default_link_type', 'file' );

As soon as we add an image from the library or by pasting into the editor, the default link is now set to Media File. If you want to link to the Media Page instead, change ‘file’ in the code above to ‘attachment’.

Thanks to Will on Stackoverflow for this snippet!

You can leave a comment on my original post.