Preserve Code Formatting

plugin banner

Version: 3.2

Preserve formatting of code for display by preventing its modification by WordPress and other plugins while retaining original whitespac

Author:Scott Reilly (profile at wordpress.org)
WordPress version required:4.9
WordPress version tested:5.7.2
Plugin version:4.0.1
Added to WordPress repository:14-04-2005
Last updated:14-04-2021
Warning! This plugin has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.
Rating, %:94
Rated by:3
Plugin URI:https://coffee2code.com/wp-plugins/preserve-c...
Total downloads:46 169
Active installs:800+
plugin download
Click to start download

This plugin preserves formatting of code for display by preventing its modification by WordPress and other plugins while also retaining whitespace.

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:

  • Prevent WordPress from HTML-encoding text (i.e. single- and double-quotes will not become curly; “–” and “—” will not become en dash and em dash, respectively; “…” will not become a horizontal ellipsis, etc)
  • Prevent most other plugins from modifying preserved code
  • Prevent shortcodes from being processed
  • Optionally preserve whitespace (in a variety of methods)
  • Optionally preserve code added in comments

Keep these things in mind:

  • ALL embedded HTML tags and HTML entities will be rendered as text to browsers, appearing exactly as you wrote them (including any br tags).
  • By default this plugin filters ‘the_content’ (post content), ‘the_excerpt’ (post excerpt), and ‘get_comment_text (comment content)’.

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


Screenshots
FAQ
ChangeLog