user3550879 user3550879 - 8 months ago 16
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;


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);