Home > Net >  wordpress add a new page or update cause The response is not a valid JSON response because of simple
wordpress add a new page or update cause The response is not a valid JSON response because of simple

Time:08-21

I am trying to make a plugin in WordPress. The plugin is working fine but when someone adds a new page or updates a page it shows an error message saying:

The response is not a valid JSON response.

I checked up the plugin code and found out it was doing that because of html part code in the file. I tried to find a fix for it but had no luck so far.

Here is the PHP plugin file, can you tell me what is wrong

<?php
/*
 * Plugin Name: test
 */
 

function testfunc () {

?>

<div >test</div>

<?php
}
add_shortcode('test','testfunc');
?>

CodePudding user response:

I think you need to buffer the output template when you create a shortcode. try this code :

<?php
/*
 * Plugin Name: test
 */
 

function testfunc () {
ob_start();
?>

<div >test</div>

<?php
return ob_get_clean();
}
add_shortcode('test','testfunc');
?>
  • Related