Skip to content
Advertisement

Invalid JSON Response due to custom wordpress shortcode

I’ve encountered a problem with a custom shortcode i created, which just outputs a table via PHP-Echo.

This shortcode just serves as a search form and posts the data to another site. Everytime i insert the shortcode in a wp-site and update it, i get “Invalid JSON-Response”.

I’ve tried some troubleshooting and found out that:

The problem just persists with that one shortcode, another custom created shortcode does not error at all. So i guess the problem really “just” lies within the shortcodes-function.

JavaScript

Here’s the form i’m rendering:

JavaScript

Any ideas on why it fails?

Advertisement

Answer

I think i’ve solved the problem myself:

  1. I’ve removed the exit-PHP-Call, which ends the script when the condition is met.
  2. I’ve added ob_start() and ob_get_clean() to the script

Since I’ve done that, there are no errors anymore and the plugin can be displayed just fine.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement