Last active
January 31, 2023 13:12
-
-
Save RiodeJaneiroo/6b73dcb44f22b4499d48df7b661ef635 to your computer and use it in GitHub Desktop.
[Wordpress Default link image media] in Gutenberg set default in image link media #wp #wordpress #gutenberg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setDefaultHrefImage() { | |
wp_enqueue_script( | |
'modify-image-link-destination-default', | |
get_template_directory_uri() . '/js/setDefaultHrefImage.js', | |
array('wp-hooks') | |
); | |
} | |
add_action('enqueue_block_editor_assets', 'setDefaultHrefImage'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function modifyLinkDestinationDefault(settings, name) { | |
if (name !== "core/image") { | |
return settings; | |
} | |
settings.attributes.linkDestination.default = "media"; | |
settings.attributes.align.default = "center"; | |
return settings; | |
} | |
wp.hooks.addFilter( | |
"blocks.registerBlockType", | |
"my-plugin/modify-linkDestination-default", | |
modifyLinkDestinationDefault | |
); |
Does JS file need to be modified to match environment?
my-plugin/modify-linkDestination-default
Tried on mine, and saddly not working
The code above works, but only on newly inserted images.
Thank you for this, it's a huge game changer!
Do someone have any idea on how to apply this default setting into images transformed from a gallery? I add a lot of photographs into my posts, and since adding them one by one is terribly long and anoying, I use a gallery block that I transform into images. But the RegisterBlockType filter isn't working anymore in that case :/
I found this filter blocks-switchtoblocktype-transformedblock but there is no documentation anywhere on how to use it...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does JS file need to be modified to match environment?
my-plugin/modify-linkDestination-default
Tried on mine, and saddly not working