skip to Main Content

The below code is not printing anything in the browser. actually, It should show the header menu.
if I remove ob_start(); and
ob_end_clean() at least its printing menu without CSS.

// Turn on output buffering HTML

ob_start();

echo preg_replace( '/n|t/i', '', implode( '' , $wr_nitro_header_html ) );

WR_Nitro_Header_Builder::prop( 'html', ob_get_contents() );

ob_end_clean()

update: same code is working fine for php7.4
but php8.1 is not working

2

Answers


  1. Your theme may not be compatible with 8.1, as there are several breaking changes introduced when migrating from 7.4 to 8.1. Try adding:

    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('WP_DEBUG_DISPLAY', true);
    

    to your wp-config.php file and see if errors print to the DOM, or make the display false and check debug.log if you are concerned about printing errors.

    Then, reach out to the theme company directly and asking if they are compatible with PHP 8.1.

    Login or Signup to reply.
  2. There is a compatibility issue because the Output Buffering has been changed in PHP 8.1

    In PHP 8.1. you have to use the new aliases instead of using the PHP 7.4 ob_* functions.

    For example:

    use function OutputControlob_start;
    use function OutputControlob_end_flush;
    use function OutputControlob_get_clean;
    
    ob_start();
    
    echo "Hello, world!";
    
    ob_end_flush();
    
    $output = ob_get_clean();
    

    Alternatively, you can use the OutputControl namespace like that:

    use OutputControl;
    
    // Enable output buffering
    ob_start();
    
    echo "Hello, world!";
    
    ob_end_flush();
    
    $output = ob_get_clean();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search