Created
December 28, 2015 02:09
-
-
Save jimmyk69/2c44a1c82ef5dc4f7cfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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