函数文档

_oembed_filter_feed_content()

💡 云策文档标注

概述

_oembed_filter_feed_content() 函数用于在 RSS 订阅源中准备 oembed HTML 内容,通过移除 iframe 元素的样式属性来优化显示。

关键要点

  • 函数接受一个字符串参数 $content,返回过滤后的字符串内容。
  • 使用 WP_HTML_Tag_Processor 遍历内容中的 iframe 标签,并移除具有 'wp-embedded-content' 类的 iframe 的 style 属性。
  • 该函数自 WordPress 4.4.0 版本引入,适用于处理 RSS 订阅源中的嵌入内容。

代码示例

function _oembed_filter_feed_content( $content ) {
    $p = new WP_HTML_Tag_Processor( $content );
    while ( $p->next_tag( array( 'tag_name' => 'iframe' ) ) ) {
        if ( $p->has_class( 'wp-embedded-content' ) ) {
            $p->remove_attribute( 'style' );
        }
    }
    return $p->get_updated_html();
}

📄 原文内容

Prepare the oembed HTML to be displayed in an RSS feed.

Parameters

$contentstringrequired
The content to filter.

Return

string The filtered content.

Source

function _oembed_filter_feed_content( $content ) {
	$p = new WP_HTML_Tag_Processor( $content );
	while ( $p->next_tag( array( 'tag_name' => 'iframe' ) ) ) {
		if ( $p->has_class( 'wp-embedded-content' ) ) {
			$p->remove_attribute( 'style' );
		}
	}
	return $p->get_updated_html();
}

Changelog

Version Description
4.4.0 Introduced.