user3550879 user3550879 - 6 months ago 8
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.

<?php
$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

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