Special character mangling in WordPress and SyntaxHighlighter

The SyntaxHighlighter WordPress plug-in is used to display code ‘as is’; unfortunately WordPress again is too clever for its own good and mangles special characters like & and ” even before the text gets to the SyntaxHighlighter blocks in the Block Editor.

The solution is to add a filter function in your custom functions.php file:

function my_syntaxhighlighter_precode( $code, $atts, $tag ) {
	if ( 'code' === $tag ) {
		$code = wp_specialchars_decode( $code, ENT_QUOTES );
	return $code;
add_filter( 'syntaxhighlighter_precode', 'my_syntaxhighlighter_precode', 10, 3 );

Source links:

Leave a Reply

Your email address will not be published. Required fields are marked *