400+
August 15, 2025
April 14, 2005
This plugin preserves formatting of code for display by preventing its modification by WordPress and other plugins while also retaining whitespace.
NOTE: This plugin does NOT handle posts containing blocks. For such posts, use the built-in code or preformatted blocks to format your code for display. However, this plugin would still be needed if you have text-based posts from before using the blocks-based editor.
NOTE: Use of the visual text editor will pose problems as it can mangle your intent in terms of code tags. I strongly suggest you not use the visual editor in conjunction with this plugin as I have taken no effort to make the two compatible.
Notes:
Basically, you can just paste code into code, pre, and/or other tags you additionally specify and this plugin will:
Keep these things in mind:
br tags).Example:
A post containing this within code tags:
$wpdb->query("
INSERT INTO $tablepostmeta
(post_id,meta_key,meta_value)
VALUES ('$post_id','link','$extended')
");
Would, with this plugin enabled, look in a browser pretty much how it does above, instead of like:
$wpdb->query(—
INSERT INTO $tablepostmeta
(post_id,meta_key,meta_value)
VALUES ('$post_id','link','$extended')
―);
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
preserve-code-formatting.zip inside the plugins directory for your site (typically wp-content/plugins/)Settings -> Code Formatting admin settings page (which you can also get to via the Settings link next to the plugin on the Manage Plugins page) and customize the settings.code tags. If you are using the block editor (aka Gutenberg), then this plugin is only useful for maintaining code formatting for posts written before WP 5.0 (or whenever you started creating posts with the block editor). You should be using the built-in code or preformatted blocks when including code into the block editor. Otherwise, if you are actively using the classic editor, be sure to use the HTML (aka “Text”) editor and not the “Visual” editor or you’ll encounter formatting issues.Are you using the visual editor? The visual editor has a tendency to screw up some of your intent, especially when you are attempting to include raw code. This plugin does not make any claims about working when you create posts with the visual editor enabled.
How to tell if you’re using the visual editor: you’re using what is now referred to as the Classic Editor (the editing experience in WordPress that pre-dates the block editor since WordPress 5.0). Above the post content field and to the right, there is a tab labeled “Visual” and another labeled “Text”. If you’re writing code, you want to use “Text” for such posts and not switch back to “Visual”.
Yes, shortcodes within code tags (or any tag processed by this plugin) will be output as pure text and not be processed as shortcodes by WordPress.
Yes, in the sense that it doesn’t do anything at all. The code and preformatted blocks in the block editor should preserve code formatting without the need for this plugin.
In short, the plugin will completely skip processing posts containing blocks. Use the code or preformatted blocks to format and display your code.
Only if you have older posts written in the text editor from before you began using the block editor. If so, then you would still want this plugin to be enabled so that those older posts have their code formatting preserved. This plugin being active will not interfere with posts created with blocks, all of which will be ignored by the plugin.
Asides from its intentional incompatibility with the block editor or classic visual editor, the main known issue with the plugin is its inability to properly recognize (and thus preserve) nested tags that match the tag being preserved. So within, for example, a tag, the first encountered will be treated as its closing tag even if technically that closing tag belongs to a nested ‘code’ tag, e.g. “This examplewith nested code tags</code> will be rendered as if that first/inner closing tag belonged to the first/outer ‘code’ tag.
It was a choice between either supporting the above scenario (which seems pretty rare overall) or supporting having multiple adjacent preserved tags in a post (which is much more common). A more robust solution is being pursued.
Yes. The tests are not packaged in the release .zip file or included in plugins.svn.wordpress.org, but can be found in the plugin’s GitHub repository. The tests are expecting to be run with PHPUnit 9 and you’ll likely experience errors if running them under another version.
Highlights:
This major release significantly improves security, performance, and compatibility. The plugin framework updates to version 070 for enhanced security and features. Block editor content is now properly excluded (the plugin was designed for text view), and compatibility extends through WordPress 6.8+ while dropping support for versions older than 5.5. Additional improvements include better error handling, enhanced documentation, and the addition of CSS classes for styling processed code blocks.
Details:
get_preprocess_regex_pattern() and get_postprocess_regex_pattern()preg_replace_callback() for tag extractionsget_c2c_string() to add new stringsREADME.md formattingHighlights:
Details:
{!{ and }!} instead of [[ and ]] to prevent interpretation as shortcodes, fixing conflict with SyntaxHighlighter. Props azito122.c2c_{PluginName}_Plugin_051 to c2c_Plugin_060get_c2c_string() as a getter for translated stringsget_c2c_string()whitelist_options() to allowed_options()add_allowed_options() instead of deprecated add_option_whitelist() for WP 5.5+allowed_options filter instead of deprecated whitelist_options for WP 5.5+is_wp_version_cmp() and get_c2c_string())is_wp_version_cmp() as a utility to compare current WP version against a given WP versioncontextual_help() to be easier to read, and correct function docblocksnumber_format_i18n() to format integer value within input fieldreadme_url() to refer to plugin’s readme.txt on plugins.svn.wordpress.orgFull changelog is available in CHANGELOG.md.
| Version | Download | Type |
|---|---|---|
| 5.0 | Download | Stable |
| 4.0.1 | Download | Stable |
| 4.0 | Download | Stable |
| 3.9.2 | Download | Stable |
| 3.9.1 | Download | Stable |
| 3.9 | Download | Stable |
| 3.8 | Download | Stable |
| 3.7 | Download | Stable |
| 3.6 | Download | Stable |
| 3.5 | Download | Stable |
| 3.2 | Download | Stable |
| 3.1 | Download | Stable |
| 3.0 | Download | Stable |
| 2.5.4 | Download | Stable |
| 2.5.3 | Download | Stable |
| 2.5.2 | Download | Stable |
| 2.5.1 | Download | Stable |
| 2.5 | Download | Stable |
| 2.0 | Download | Stable |
| Development | Download | Trunk |