Wordpress - 发布没有块引用或图像的内容
Wordpress - posting content without blockquote or images
尝试 post post 的内容,但没有块引用或图像。我的代码取出了图像,但仍然放入块引用和文本。
<?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;
?>
这里有一个简单的错误 - 你对 preg_replace()
的第二次调用使用的是 get_the_content()
,这是未修改的内容 - 所以你基本上是在取消你在第一行所做的事情。
为了让第二行使用第一行的输出,你的第二个参数需要是$content
:
$content = preg_replace('/(<img [^>]*>)/', '', $content);
尝试 post post 的内容,但没有块引用或图像。我的代码取出了图像,但仍然放入块引用和文本。
<?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;
?>
这里有一个简单的错误 - 你对 preg_replace()
的第二次调用使用的是 get_the_content()
,这是未修改的内容 - 所以你基本上是在取消你在第一行所做的事情。
为了让第二行使用第一行的输出,你的第二个参数需要是$content
:
$content = preg_replace('/(<img [^>]*>)/', '', $content);