Note: I am using https://wordpress.org/plugins/classic-editor/ with latest updated WordPress.
I have a Blog at https://www.exeideas.com/ and I share code snippet here also that was working before perfectly as I share the Escaped Codes inside <pre> and <code> tag but suddenly it started executing codes inside the <pre> and <code> tags all over my blog for example at https://www.exeideas.com/2022/10/responsive-collapsible-sidebar-and-tab-nav.html
It was working till yesterday. Any way to fix this all over my blog where I have about 3800+ articles that contain <pre> and <code> tags, I tried the following solutions but was not successful...
functions.php
add_filter( 'the_content', 'pre_content_filter', 0 );
function pre_content_filter( $content ) {
return preg_replace_callback( '|<pre.*>(.*)</pre|isU' , 'convert_pre_entities', $content );
}
function convert_pre_entities( $matches ) {
return str_replace( $matches[1], html_entity_decode( $matches[1] ), $matches[0] );
}
functions.php
add_filter('the_content','pre_esc_html',9);
function pre_esc_html($content) {
return preg_replace_callback(
'#(<pre.*?>)(.*?)(</pre>)#imsu',
create_function(
'$i',
'return $i[1].esc_html($i[2]).$i[3];'
),
$content
);
}
single.php
<?php
function escapeRecursively($node) {
if ($node instanceof DOMText)
return $node->textContent;
$children = $node->childNodes;
$content = "<$node->nodeName>";
for ($i = 0; $i < $children->length; $i += 1) {
$child = $children->item($i);
$content .= escapeRecursively($child);
}
return "$content</$node->nodeName>";
}
function escapePreformattedCode($html) {
$doc = new DOMDocument();
$doc->loadHTML($html);
$pres = $doc->getElementsByTagName('pre');
for ($i = 0; $i < $pres->length; $i += 1) {
$node = $pres->item($i);
$children = $node->childNodes;
$content = '';
for ($j = 0; $j < $children->length; $j += 1) {
$child = $children->item($j);
$content .= escapeRecursively($child);
}
$node->nodeValue = htmlspecialchars($content);
}
return $doc->saveHTML();
}
?>
<div class="post">
<?php echo escapePreformattedCode(the_content()); ?>
<div class="clear"></div>
</div>
But none of this is working. This happen to all of my old posts too that were working yesterday. What were the fix to it and avoid editing all 3800+ posts...
<pre><code>
instead of<pre>
? Things don't suddenly change out of nowhere, something was modified/changed/updated, what has changed since yesterday?<?php the_content(); ?>
in my theme