skip to Main Content

When I try to display a shortcode in pages it shows this ‘Updating failed. The response is not a valid JSON response’ error but the page gets updated and no error shows in the frontend. When I use the classic editor it works fine but issues with block editor.

Here its code

<?php
class EmailPluginfront {

    function __construct() {
        
        add_shortcode('email', array($this,'front_display'));  
        
    }  
function front_display() {
                   
echo '<h2 style="text-align:center; margin-bottom:30px">'.get_option('email_title_field').'</h2>';
}
}
$EmailPluginfront = new EmailPluginfront();

2

Answers


  1. you need to return data at the end of your function. try using this in your shortcode function

    ob_start();
    echo("Hello there!"); // all your code here
    $output = ob_get_contents();
    ob_end_clean();
    return $output
    
    Login or Signup to reply.
  2. Can you please use ‘return’ instead of the ‘echo’?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search