我有一个Wordpress网站,我想从帖子中删除块引用并只放置常规文本。 (还想删除文本中的任何图像,我只想要常规文本)
此代码执行我想要的OPPOSITE - 取出块引号和帖子。我希望它发布其他文本而不是块引用。
find
答案 0 :(得分:1)
您需要的是内容过滤器。将以下内容添加到functions.php文件
中add_filter( 'the_content', 'rm_quotes_and_images' );
function rm_quotes_and_images($content)
{
$content = preg_replace("~<blockquote>([\s\S]+?)</blockquote>~", "", $content);
$content = preg_replace("/<img[^>]+>/i", "", $content);
return $content;
}
答案 1 :(得分:0)
试试这个
add_filter( 'the_content', 'block_the_content_filter' );
function block_the_content_filter($content) {
$content = preg_replace("~<blockquote>([\s\S]+?)</blockquote>~", "", $content);
return $content;
}
答案 2 :(得分:0)
只需将其添加到您的代码中:
$content = preg_replace("~<blockquote>([\s\S]+?)</blockquote>~", "", $content);
$content = strip_tags($content, '<img>');
echo $content;
wali hassan所说的方法是将以下代码添加到你的function.php:
add_filter( 'the_content', 'block_the_content_filter' );
function block_the_content_filter($content) {
$content = preg_replace("~<blockquote>([\s\S]+?)</blockquote>~", "", $content);
$content = strip_tags($content, '<img>');
return $content;
}
这会覆盖默认的&#34; the_content()&#34;功能所以在你的页面模板中你只需要打电话:
the_content();