All posts in Uncategorised
RegEx Replacement in WordPress Content
Just call this function:
function reg_replace_content( $szPattern, $szReplace, $bPrint = false )
{
global $post;
$szPostContent = $post->post_content;
$szPostContent = preg_replace( $szPattern, $szReplace , $szPostContent );
apply_filters( 'the_content', $szPostContent );
if ( $bPrint == false ) return $szPostContent; else echo $szPostContent;
}
like so:
// Search '~<p[^>]*>\s?</p>~' ( remove empties <p> ) and print the content.
<?php if ( function_exists( 'reg_replace_content' ) ) reg_replace_content( '~<p[^>]*>\s?</p>~', '', true ); ?>

Web professional in Malta, Europe. Focusing on building visually stunning websites that are easy to maintain, usually using WordPress as the CMS. Web developing since 1995, loving WordPress for more than 5 years.