Do you want to stop WordPress from automatically formatting your posts?
By default, WordPress changes text to replace quotes with fancy quotes and cleans up the text. This can prevent you from displaying code, raw text, and CSS/JavaScript examples.
In this article, we’ll show you how to disable automatic formatting in WordPress posts.
Why Disable WordPress Formatting in Posts?
WordPress has a feature that sanitizes text. This feature replaces quotes with fancy quotes and removes certain tags needed to display HTML, CSS, or JavaScript properly.
There are various ways to display code in WordPress without the default formatting, which you can learn from our article on how to display code in WordPress.
However, some advanced users might want to completely disable WordPress auto-formatting. This allows them to display raw text without WordPress formatting checks.
Here’s how to disable automatic WordPress formatting. We’ll show you two methods, so you can choose the best one for your needs.
Method 1: Manually Disable Automatic Formatting in WordPress
This method involves adding custom code to your WordPress site. If you haven’t done this before, check our guide on how to copy and paste custom code snippets in WordPress.
First, paste the following code into your theme’s functions.php
file or a code snippets 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);
We recommend using the WPCode plugin to add this code. It’s the safest and easiest way to add custom code in WordPress without editing your theme files.
To start, install and activate the free WPCode plugin. If you need help, see this guide on how to install a WordPress plugin.
Once the plugin is activated, go to Code Snippets » Add Snippet from your WordPress dashboard. Hover over the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button.
Next, add a title for your snippet to help you remember what the code does. Paste the code above into the ‘Code Preview’ box and select ‘PHP Snippet’ as the code type from the dropdown menu.
Finally, toggle the switch from ‘Inactive’ to ‘Active’ and click the ‘Save Snippet’ button at the top of the page.
This code tells WordPress to skip formatting if the text is wrapped inside the raw shortcode. To skip WordPress formatting, add the HTML block to your WordPress post editor and place your unformatted text or code inside the raw shortcode like this:
The downside of this method is that it may not work well with the block editor and could behave unexpectedly even inside the HTML block.
Method 2: Disable Automatic Formatting Using a Plugin
This method is easier but requires using the older Classic Editor plugin. The main drawback is that it might create issues if you switch to the block editor in the future.
First, install and activate the Classic Editor plugin. For more details, see our guide on how to disable the block editor in WordPress.
Next, install and activate the Raw HTML plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.
Now, create a new post or edit an existing one. On the post edit screen, switch to Text mode and add your unformatted text inside the raw shortcode like this:
Publish or save your changes and preview them to see the unformatted text.
We hope this article helped you learn how to disable automatic formatting in WordPress posts. You might also want to see our guide on how to highlight text in WordPress or our picks of the best WordPress jQuery plugins.