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

- by

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!



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.