WordPress turns HTML code to HTML entities

I created a new wordpress page and added this into the Text tab (NOT the visual tab. The visual tab is disabled):

<div></div>

When I click Publish, the code turns into this:

&lt;div&gt;&lt;/div&gt;

How do I stop it from doing that?? The website displays the code like text and not HTML, so you literally see “&lt;div&gt;&lt;/div&gt;” on the page. I even tried adding a replace script into the functions.php file and it didn’t work:

function my_content_filter( $content ) {
    $new_content = str_replace('&gt;','>',$content);
    return $new_content;
}
add_filter( 'the_content', 'my_content_filter', 1 );

I should also note that I have tried to use a shortcode/snippet plugin to add HTML to the page and it still comes out with entity code.

1 Answer
1

I’m 99% certain you’re editing in the Visual tab and need to be adding HTML in the Text tab. Change to the Text tab in the upper right and paste the HTML code in there.

If for some insane reason this is happening from the Text tab, disable all plugins and themes and make sure it’s not one of them causing it.

If it’s still happening, peace be with you, and add this to your functions:

function dawn_content_filter( $content ) {
    return html_entity_decode( $content );
}
add_filter( 'the_content', 'dawn_content_filter', 1 );

For the editor, you can use this function to convert the content that’s displayed in the editor. Keep in mind this will prevent you from being able to display code samples on your site because it will convert html entities into parseable html code. I’d still recommend checking for plugin/theme issues to make sure the issue doesn’t reside there.

function dawn_editor_filter( $content ) {
    return html_entity_decode( $content );
}
add_filter( 'the_editor_content', 'dawn_editor_filter', 1 );

Leave a Comment