prevent "&" from being converted to "&" in the gutenberg shortcode block

hi Guys.

I am adding an image URL directly in the Gutenberg shortcode block and it is using & in the URL, after the page is saved and refreshed the & is converted to & and breaks the URL, is there a way to prevent this?

Thank you.

Something like this but it breaks the block…

function gutenberg_shortcode_block_editor_assets() {
‘wp.hooks.addFilter( “blocks.getSaveElement”, “gutenberg_shortcode_block”, function( element, blockType, attributes ) {
if ( === “core/shortcode” && attributes.shortcode.indexOf(“[fwdsap”) !== -1 ) {
var div = document.createElement( “div” );
div.innerHTML = attributes.content;
var decodedText = div.firstChild.getAttribute( “text” );
div.firstChild.setAttribute( “text”, decodedText.replace( /&/g, “&” ) );
attributes.content = div.innerHTML;
return element;
} );’
add_action( ‘enqueue_block_editor_assets’, ‘gutenberg_shortcode_block_editor_assets’ );


I checked on this in Gutenberg and it is happening for me also, without any plugin activated, with latest WordPress version. I looked this up and indeed, some other people also reported this as a Gutenberg Editor bug, check below (the first issue listed below is currently still open, commenting on it might be helpful, so it can get more attention):

I think the cleanest solution is to wait for the Gutenberg team to solve this issue, however, if solving this is urgent for you, if the shortcode was created by you, I recommend modifying it, so it expects the & characters being encoded in the URL, so the shortcode can decode them, using htmlspecialchars_decode. Another option, if possible, is to modify the shortcode to not be needed to add the URL parameters directly in the URL, but in a separate shortcode parameter, as suggested here:

I hope this helps.


Thank you for your help!

1 Like

I have changed the shortcode to this format and it is better Problem with Gutenberg escaping shortcode attributes |

Thank you for your help Szabi!

1 Like

This is the plugin I need it for Spectrum Audio Player by FWDesign | CodeCanyon

1 Like

I am glad to help. :slight_smile:

1 Like