Design TipsWordPress Tips

Disable WordPress Auto Formatting Using Short Code

WordPress Tips by Ideas and Pixels

Anyone who has worked with WordPress knows how bad the automatic formatting can when you are creating your pages or posts. This will work when the WordPress plugin, PS Disable Auto Formatting, will not.

Thankfully, after hours of testing and looking for helpful advice we stumbled on the best solution; to our amazement it is just a bit of short code.

This short code will disable only the selected portions of text that you do not wish WordPress to auto format, solving this annoying WordPress auto formatting problem!

Place this code within your functions.php file using the standard PHP Layout:

$new_content = ''; $pattern_full =
'{(\[raw\].*?\[/raw\])}is'; $pattern_contents =
'{\[raw\](.*?)\[/raw\]}is'; $pieces =
preg_split($pattern_full, $content,
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); ?>

Then all you have to do within your WordPress, posts or pages, is block of the sections of text that you do not wish to have the WordPress auto format, using [RAW] tags: [raw]Place the RAW TAGS around the text you do not wish
to have auto formatted, as it is done here![/raw]

Many thanks to TheBinaryPenguin for posting this solution!

Join the discussion 28 Comments

Leave a Reply

Matt Valvano

Author Matt Valvano

Matt has a very extensive experience of print and web design. He is an effective team player known for creativity, flexibility, distributing skills, managing, working with others and producing high quality, effective works of art within a deadline.

More posts by Matt Valvano

Join the discussion 28 Comments

Leave a Reply