Skip to content

Instantly share code, notes, and snippets.

@AbhishekGhosh
Created August 20, 2014 17:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbhishekGhosh/d0606048916baafe7826 to your computer and use it in GitHub Desktop.
Save AbhishekGhosh/d0606048916baafe7826 to your computer and use it in GitHub Desktop.
Convert Backticks to Code Sparing Pre Block
function tcw_the_content( $content ) {
$content = preg_replace_callback('/<pre>(.*?)<\/pre>/s', function ($match) {
return '<pre>' . preg_replace('/`/', '\`', $match[1]) . '</pre>';
}, $content);
$content = preg_replace( '/`(.*?)`/', '<code>$1</code>', $content );
return $content;
}
add_filter( 'the_content', 'tcw_the_content' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment