user3550879 user3550879 - 1 year ago 93
PHP Question

Wordpress - posting content without blockquote or images

Trying to post the content of a post WITHOUT the blockquote or images. My code takes out the images but still puts in the block quote and text.

$content = preg_replace('/<blockquote>(.*?)<\/blockquote>/', '', get_the_content());
$content = preg_replace('/(<img [^>]*>)/', '', get_the_content());
$content = wpautop($content); // Add paragraph-tags
$content = str_replace('<p></p>', '', $content); // remove empty paragraphs
echo $content;

Answer Source

Simple error here - your second call to preg_replace() is using get_the_content(), which is the unmodified content - so you're basically doing away with what you did on your first line.

For the second line to use the output of the first line, your second parameter needs to be $content:

$content = preg_replace('/(<img [^>]*>)/', '', $content);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download