disable automatic formatting in WordPress posts og

Do you want to turn off automatic post formatting in WordPress?

Advertisements

in this article we will learn how to turn Off Automatic Post Formatting in WordPress

WordPress automatically formats content to replace quotes with fancy quotes and tidy it up. This disables the display of code, raw text, and CSS/Javascript code examples for users.

We’ll show you how to prevent automatic formatting in WordPress articles in this article.

How to Disable Automatic Formatting in WordPress Posts

Why is it necessary to turn off WordPress formatting in WordPress posts?

Sanitize text is a built-in feature in WordPress. This feature replaces quotations with fancy quotes and removes any tags that would be needed to show HTML, CSS, or JavaScript.

 

There are a variety of ways to show code in WordPress that allow you to bypass the default formatting. You may find them in our guide to displaying code in WordPress.

 

Some expert users, on the other hand, may wish to totally disable WordPress auto-formatting on their sites. This would enable users to simply bypass WordPress’s formatting checks and show raw text wherever they wanted on their website.

Let’s have a look at how you may quickly deactivate automatic WordPress formatting on your website. We’ll demonstrate two approaches so you may choose the one that best suits your needs.

Method 1: Disable automatic formatting in WordPress manually.

This solution necessitates the addition of custom code to your WordPress site. Take a look at our instruction on how to copy and paste custom code snippets in WordPress if you haven’t done so before.

Advertisements

To begin, enter the following code into your theme’s functions.php file or a site-specific plugin’s functions.php file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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);

 

If some text is wrapped inside the raw shortcode, the above code tells WordPress to skip the formatting choice.

You must now add the HTML block to your WordPress post editor in order to skip WordPress formatting. You can paste your unformatted text or code into the raw shortcode in the post editor.

1
[raw]Unformatted code[/raw]

Unformatted HTML block

The drawback of this strategy is that it is incompatible with the block editor. It may act in an unanticipated way even within the HTML block.

Method 2: Using a plugin, disable automatic formatting in WordPress.
This way is simpler, but it necessitates the usage of the Classic Editor plugin, which is no longer supported. The primary problem of this strategy is that if you decide to use the block editor in the future, you’ll end up with a mess.

The Classic Editor plugin must first be installed and activated. See our guide on how to disable the block editor in WordPress for more information.

The Raw HTML plugin must then be installed and activated. See our step-by-step guide on installing a WordPress plugin for more information.

After then, you may either create a new post or edit one that already exists. Switch to Text mode on the post edit screen and type your unformatted text into the raw shortcode.

1
[raw]Unformatted code[/raw]

Unformatted classic editor

You can now publish or save your changes and examine them in a preview window to see how unformatted text looks.

We hope that this article taught you how to turn off automatic formatting in WordPress posts. You might also be interested in our entire WordPress security guide or our SEO tips for blog posts.

Advertisements

Leave a Reply