A shortcode should only ever return
content, never echo
it. The bits between the ?>
and <?php
tags — the <script>
tags and the rest — are effectively being echo
ed to the browser, which means that the JSON content that Gutenberg expects is no longer valid.
From the add_shortcode()
docs:
Note that the function called by the shortcode should never produce an output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results.
Also, instead of sending those <script>
tags directly, you should enqueue them. See wp_enqueue_script()
. Since you are passing data from PHP to at least one of your scripts, see also wp_localize_script()
.
Related Posts:
- How to handle shortcodes when using the JSON API
- Using get_option() in JavaScript
- Tinymce – How to hook before or after live shortcodes rendering?
- How execute shortcode with javascript
- WP_enqueue_script inside shortcode?
- Shortcode to Gutenberg-block: additional text on front-end and conditional display
- How to enqueue script based on post category?
- Pass javascript array to shortcode
- Add custom setting that uses radio button to WP Gallery
- Convert HTML Script to Shortcode [closed]
- Preserve shortcode content formatting
- Get Required Assets (JS, CSS etc) for post using REST API
- Gutenberg Block with Select from JSON-File
- Scripts for shortcode: concatenate or load separately? [closed]
- Adding javascript actions to words in post content
- Add JS in footer via shortcode?
- Regenerating WordPress shortcodes based on value with AJAX
- WP REST API remove the WordPress shortcodes from the JSON wp/v2/posts content->rendered
- pass complex json as shortcode parameter
- Displaying an interactive web map on my wordpress site
- Third-Party API – PHP Fatal Errors Paired with http_request_failed / cURL error 28
- Multiple shortcodes with embedded JavaScript code in same page, how?
- Simulate shortcodes with javascript
- wp_register_script and wp_register_style when shortcode is used
- Why does my JavaScript work in the browser console but does not work in my shortcode?
- get_queried_object_id / short code returning blank
- Video shortcode, option are not rendered
- ACF repeater + group shortcode
- Custom shortcode skips every 2nd shortcode
- How to write a shopping queue line plugin with a queue button?
- Create shortcode for each form field in contact form 7
- how to use nimble-API and Display data?
- Build Clickable Link Using Multiple Attributes
- Set redirect for need login
- Getting Shortcode Attributes befor content is displayed by the template
- make user_id in a shortcode dynamic based on who’s logged in
- How to add site tags in alphabetical order to shortcode?
- How can i strip shortcode from HTML title tag?
- Can’t render shortcode when html tag contains hyphen
- Adding shortcode of “Random Content” Plugin in the post after the title
- Shortcode won’t take into account custom post ID put in parameter
- using shortcodes inside gravity forms
- wordpress script_loader_tag in function.php
- Show content if user left comment / non-logged visitors?
- How to insert current user ID/entry ID into a shortcode?
- Upload Javascript and json webpage to wordpress
- How to remove double quotes in a shortcode?
- Auto embeds don’t work for attachment descriptions
- Shortcode to appear and show the date not code in Title and description of my website
- Template not loading with get_template_part or locate_template
- Shortcode to appear and show the date not code in Title and description of Social Media sites
- Need help with creating a simple shortcode
- Colon is Missing In My Website Url in WordPress Shortcode
- WordPress post shortcode pagination not working
- Wrap template code with shortcodes
- my form does not insert any data in the database
- Using Shorcodes in Sharing Preview and Notifications Title from Post Title
- Not to escape a text
- Using shortcodes in the Site Title
- Returning HTML to Shortcode Block
- Use atributes of shortcode in get template part
- Global $post returns 2 objects for my shortcode
- How to display html element and php string in the same line?
- How to Display Shortcode’s Content after Short Product Description?
- Echo Extra Shortcode HTML to wp_foot
- How can I use a plugin shortcode inside of a html form?
- Gutenberg Shortcode Chooser Block
- Image Caption Shortcode Broken upon update
- How to cache a custom API call?
- Using a WP shortcode in Homepage
- Shortcode do not return a value
- i want to show a modal when user lands on home page very first time
- Check if parent page has child page of certain slug
- Shortcode not working in CPT taxonomy
- Shortcode not working inside div html
- Is the WP audio shortcode still relevant?
- wp_enqueue_scripts does not work on admin page
- shortcode containing other shortcodes not returning content
- Problem parsing long parameter in shortcode
- Variable inside shortcode or shortcode inside shortcode
- How to utilise multiple values from a single shortcode attribute?
- JavaScript missing from shortcode content
- Hide download option video shortcode
- Can Someone Help me to Correct my shortcode for displaying a category?
- WordPress Shorcode Display hierarchical taxonomy [child, parent]
- From a shortcode I want to pass a value to display a different page
- Shortcode not working in Jetpack Top Posts & Pages widget
- How to include shortcodes and pdfs in WordPress search without plugin?
- Color on Shortcode insert that creates a button
- shortcode doesnt work on excerpt
- Adding Author URL to Nav Menu via Shortcode
- Restricting shortcode for users
- How to embeded shortcode for another website
- Disable wpautop on Shortcode attributes
- shortcode to display specific recent posts
- Date Shortcode in Image alt and title tags
- access shortcode atts in template part
- How to test If a post has a particular term
- Why does my custom plugin only function correctly once per page?
- How to use multiple (or array) values in $content of shortcode?