I’m struggling with creating a shortcode to pull images from posts with a certain tag.
This code has been working, but it’s now failing with the "Updating failed. The response is not a valid JSON response." error in an error bar across the top of the page when saving the posts/pages that include the shortcode.
I’m using the gutenburg editor, and the issue seems like it started when I added the shortcode into a paragraph block. At the time I changed it to a /shortcode block, entered the shortcode, and all good – but ony for a short while.
I’ve tried removing all of the code but the issue remains.
I was expecting the the code not to run in the editing screen – I think that this is the cause of the issue.
2
Answers
OK - I found this post
putting this at the top of the function called by the shortcode stops the code from running if the call is a REST REQUEST:
fixed. https://wordpress.stackexchange.com/a/390391/241222
Thank
WordPress related, given the terms "Gutenberg" and "shortcode" yes? You may wish to tag this accordingly. Good luck!