Wordpress - 发布没有blockquote或图像的内容

问题描述:

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

尝试发布没有blockquote或images的帖子内容。 我的代码取出图像,但仍然放入块引号和文本。 p>

 &lt;?php 
 $ content = preg_replace('/&lt; blockquote&gt;(。*  ?)&lt; \ / blockquote&gt; /','',get_the_content()); 
 $ content = preg_replace('/(&lt; img [^&gt;] *&gt;)/','',get_the_content()  ); 
 $ content = wpautop($ content);  //添加paragraph-tags 
 $ content = str_replace('&lt; p&gt;&lt; / p&gt;','',$ content);  //删除空段落
 echo $ content; 
?&gt; 
  code>  pre> 
  div>

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