我只想显示文本,不想显示图像。值得注意的是,我不想删除 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');
但它对我不起作用。
请试试这个脚本。这未经测试,但希望对您有用。
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');
或查看此链接http://www.wpworking.com/hacks-2/remove-first-image-from-wordpress-post/
此脚本将搜索内容并从您的帖子中删除第一张图片。这里preg_replace()
函数搜索图像标签并从内容中删除第一次出现。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句