Disable Automatic Formatting Using a Shortcode


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function my_formatter($content) {       
  2. $new_content = '';       
  3. $pattern_full = '{(\[raw\].*?\[/raw\])}is';       
  4. $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';       
  5. $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);       
  6. foreach ($pieces as $piece) {               
  7. if (preg_match($pattern_contents, $piece, $matches)) {                       
  8. $new_content .= $matches[1];               
  9. } else {                       
  10. $new_content .= wptexturize(wpautop($piece));               
  11. }       
  12. }       
  13. return $new_content;
  14. }
  15. remove_filter('the_content', 'wpautop');
  16. remove_filter('the_content', 'wptexturize');
  17.  
  18. add_filter('the_content', 'my_formatter', 99);

URL: http://css-tricks.com/snippets/wordpress/disable-automatic-formatting-using-a-shortcode/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.