Website Scripts And Cloud Tutorials

migrate GD star to YASR plugin in WordPress

Last updated on January 23rd, 2022 at 09:44 am

Click to rate this tutorial!
[Total: 0 Average: 0]

How to remove WordPress HTML entities | special characters in posts

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 🙂

Click to rate this tutorial!
[Total: 0 Average: 0]

Leave a Reply

Your email address will not be published.