2

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

O. Jones
  • 103,626
  • 17
  • 118
  • 172
sivakumar
  • 49
  • 1
  • 1
  • 13

2 Answers2

0

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.

Marsellus
  • 93
  • 3
  • 12
-1

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 OutputControl\ob_start;
use function OutputControl\ob_end_flush;
use function OutputControl\ob_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();
Dev Błack
  • 51
  • 5
  • Hi, I'm using this code since a while [link](https://pastebin.com/aFBPSt6P), but I'm failing to address Twitter/Reddit embed strings or the iFrame code they're creating (GTag works). In addition I'm getting this error: `PHP Notice: ob_end_flush(): Failed to delete and flush buffer. No buffer to delete or flush in [...]child/functions.php` (using WP 6.0.3, PHP 8.1.13) I'm getting PHP deprecated errors too, but as long as everything is working it's not too bad, right? Could you, by any chance, help me to tweak the code of your example to my use case? – eCronik Dec 22 '22 at 09:35