Skip to content

Instantly share code, notes, and snippets.

@IronGhost63
Last active February 6, 2020 13:55
Show Gist options
  • Save IronGhost63/11120908426d63b7495da403c3fd0cf1 to your computer and use it in GitHub Desktop.
Save IronGhost63/11120908426d63b7495da403c3fd0cf1 to your computer and use it in GitHub Desktop.
Gutenberg image block - default link destination
(function(wp) {
wp.hooks.addFilter(
"blocks.registerBlockType",
"my-plugin/modify-linkDestination-default",
function (settings, name) {
if (name === "core/image") {
settings.attributes.linkDestination.default = "media";
} else if ( name === "core/gallery" ) {
settings.attributes.linkTo.default = "media";
}
return settings;
}
);
})(window.wp)
<?php
add_action( 'enqueue_block_editor_assets', function() {
wp_enqueue_script( 'block-image', 'path/to/block-image.js' );
} );
@artmaug
Copy link

artmaug commented Feb 6, 2020

Thank you, works perfect

@artmaug
Copy link

artmaug commented Feb 6, 2020

Sorry, only works with gallery block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment