Set default image link target in Gutenberg image block

This was (finally) fixed to Gutenberg (and will be applicable for both the image and the gallery blocks); and will add an option to WordPress options’ database table.
this was done in
https://github.com/WordPress/gutenberg/pull/25578 and https://github.com/WordPress/gutenberg/pull/25582

It’ll be added to WordPress 5.6 but it’s already available in the Gutenberg plugin.

To link the image to the file by default, issue the following in your theme or plugin:

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

Replace file with attachment if you want to link to the attachment page for some reason, or none if you don’t want to the image to have a link.

As for javascript: modifying blocks so that they alter the site’s options is possible in Gutenberg although I haven’t gotten it to work yet, check out:
https://github.com/WordPress/gutenberg/issues/20731

Note that if you try do the image_default_link_type equivalent in javascript, don’t use “file” and “post” as the options (as long as this ticket is open) – see https://github.com/WordPress/gutenberg/issues/25587

Leave a Comment