Skip to content

Instantly share code, notes, and snippets.

@jimmyk69
Created December 28, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmyk69/2c44a1c82ef5dc4f7cfd to your computer and use it in GitHub Desktop.
Save jimmyk69/2c44a1c82ef5dc4f7cfd to your computer and use it in GitHub Desktop.
//disabling WordPress’s auto-formating filters ( get rid of p tags, br tags, etc.. )
function rm314_formatter($content) {
$new_content = '';
/* Matches the contents and the open and closing tags */
$pattern_full = '{(\[raw\].*?\[/raw\])}is';
/* Matches just the contents */
$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
/* Divide content into pieces */
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
/* Loop over pieces */
foreach ($pieces as $piece) {
/* Look for presence of the shortcode */
if (preg_match($pattern_contents, $piece, $matches)) {
/* Append to content (no formatting) */
$new_content .= $matches[1];
} else {
/* Format and append to content */
$new_content .= wptexturize(wpautop($piece));
}
}
return $new_content;
}
// Remove the 2 main auto-formatters
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
// Before displaying for viewing, apply this function
add_filter('the_content', 'rm314_formatter', 99);
add_filter('widget_text', 'rm314_formatter', 99);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment