Last updated on January 4th, 2023 at 06:27 pm

It is annoying to see your WordPress post displaying HTML Entities instead of actual code results. For example it will display & gt; for > and & lt; for < symbol. How to fix this without using a Plugin. The function below is not that greatly done but will do the trick. Go to your themes directory (Which ever theme you are currently using) and edit the functions.php file. Make a backup of this file before you proceed. Go to the end of the file and add these lines, Then save the file.

WordPress replace HTML entities in posts

function my_content_filter( $content ) {
    $new_content = str_replace('&gt;','>',$content);
    $new_content1 = str_replace('&lt;','<',$new_content);
    $new_content2 = str_replace('&quot;','"',$new_content1);
    $new_content3 = str_replace('&amp;','&',$new_content2);
    return $new_content3;
add_filter( 'the_content', 'my_content_filter', 1 );

Function above is self explanatory, All we are doing is replacing the symbols with the actual results and returning the updated content in variable $new_content3, Then we are adding filter using add_filter().

Hope this will help at least some of you out there who has the same issue 🙂

Leave a Reply

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