How to Disable Automatic Formatting in WordPress

How to Disable Automatic Formatting in WordPress

To know how to disable automatic Formatting in WordPress, go through the text below. This will allow you to skip the WordPress formatting checks and show raw text on your website.

WordPress always auto-formates HTML when you add text in the editor. It automatically formats text to clean up and replaces simple quotes with fancy quotes. Also, it removes tags required to display HTML, javascript, or CSS. Therefore this auto-formatting stops users from displaying raw text, code, and CSS/Javascript code.

Without any delay, let us explain how to disable autoformatting in WordPress.

1. Disable Automatic Formatting by coding

You have to add custom code to your WordPress website in this method.
Now, copy and paste the following code to your theme’s functions.php file or a site-specific plugin.

function my_formatter($content) {
$new_content = '';
$pattern_full = '{([raw].*?[/raw])}is';
$pattern_contents = '{[raw](.*?)[/raw]}is';
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

foreach ($pieces as $piece) {
if (preg_match($pattern_contents, $piece, $matches)) {
$new_content .= $matches[1];
} else {
$new_content .= wptexturize(wpautop($piece));
}
}

return $new_content;
}

remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');

add_filter('the_content', 'my_formatter', 99);

The above code helps you skip the formatting option of the wrapped text inside the raw shortcode, and you must add the HTML block to your WordPress post editor.

You can add your unformatted text or code inside the raw shortcode inside the post editor.

[raw]Unformatted code[/raw]

 

The drawback of this coding method is that it does not work well with the block editor. Even in the HTML block, it may act unexpectedly.

Now, Let us move on to the another method to disable automatic formatting.

2. Disable Automatic Formatting by using a plugin

You can use the Raw HTML plugin. It is an easy-to-use, lightweight plugin that helps you disable automatic Formatting in WordPress.
After installing the plugin, you can wrap any page or post in the code generated by the plugin. Simply wrapping content with this code will prevent WordPress from converting newlines to HTML paragraphs.

This Raw HTML Plugin method is easier, but it works with Classic Editor. Also, you have to stay on the Text editor tab.

The main disadvantage of this approach is that it would create a mess if you decide to start using the block editor in the future.

Note- The plugin’s free version only supports editing posts in the HTML editor (text editor) in WordPress. If you want to change the text editor with a visual editor without messing up content, you have to use the pro version of this plugin. Also, this plugin does not fully support the Gutenberg editor.

Now, let us move how you can do it. Follow the steps below and disable auto-formatting in WordPress.

To install plugins you can check our guide to install a plugin or follow these steps.

Go to plugins >> search new >> search for the Raw HTML

After installing and activating the Raw HTML Plugin,  now, create a new post.


Go to posts >> add new.

Now, go to the “text” tab and create your content. You have to create your content in a Text/HTML editor.
Wrap the content between the following code, which will prevent your content from formatting.

[raw]content here[/raw] or <!—raw–>content here<!–/raw–> tags.

Moreover, This plugin provides certain checkboxes options below the page. You can use any of the options according to your need.
Now go ahead and publish your content or save your changes and preview it to see unformatted text in action.

 

To wrap up, The Auto-Formatting of HTML in WordPress creates an issue with the content. You can disable automatic formatting in WordPress by using different methods.

You can use manual code or use the Raw HTML plugin.

we really hope this article helped you. You can also check our post on how to disable HTML in WordPress comments.

Leave a Comment