Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 从提要内容中删除第一个图像_Wordpress_Feed - Fatal编程技术网

Wordpress 从提要内容中删除第一个图像

Wordpress 从提要内容中删除第一个图像,wordpress,feed,Wordpress,Feed,我只想显示文本,不想显示图像。值得注意的是,我不想删除img属性 我该怎么做?我试过: <img class="pagehead" src="/graphics/magazine/307/1.jpg" alt="" /> function remove_first_image ($content) { if (is_feed()) { $content = preg_replace("/<img[^>]+\>/i", "", $conten

我只想显示文本,不想显示图像。值得注意的是,我不想删除img属性

我该怎么做?我试过:

<img class="pagehead" src="/graphics/magazine/307/1.jpg" alt="" />

function remove_first_image ($content) {
    if (is_feed()) {
        $content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
    } 
    return $content;
}
add_filter('the_content_rss', 'remove_first_image');
add_filter('the_content', 'remove_first_image');

函数删除第一个图像($content){
if(is_feed()){
$content=preg\u replace(“/]+\>/i”,”,$content,1);
} 
返回$content;
}
添加过滤器(“内容rss”,“删除第一个图像”);
添加过滤器(“内容”,“删除第一个图像”);

但是它对我不起作用。

请试试这个脚本。这是没有测试,但希望将为您工作

function remove_first_image ($content) {
      if (!is_page() && !is_feed() && !is_feed() && !is_home()) {
        $content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
      } 
    return $content;
    }
    add_filter('the_content', 'remove_first_image');
函数删除第一个图像($content){
如果(!is_page()&&!is_feed()&&!is_feed()&&!is_home()){
$content=preg\u replace(“/]+\>/i”,”,$content,1);
} 
返回$content;
}
添加过滤器(“内容”,“删除第一个图像”);
或查看此链接


此脚本将搜索内容并从帖子中删除第一个图像。此处
preg\u replace()
函数搜索图像标记并从内容中删除第一个出现的内容。

定义“不工作”:导致错误?截断HTML使其不再有效?您可能希望替换
请考虑使用
节选内容\u rss
而不是
内容\u rss
,该内容已被删除。请尝试此脚本。这并没有经过测试,但希望对你们有用。@nicolas cami我也这么做problem@nicolallias我不知道你在说什么!!请试试这个脚本。这没有经过测试,但希望对您有用。@JordanLeigh,您面临的问题是什么?它必须删除第一个img标记,但您的代码不能这样做。请查看此链接@JordanLeigh,我很高兴帮助您。