对于包含Youtube网址的帖子,我正在尝试从我们的Wordpress网站生成的RSS Feed中删除iframe .

我只是想将youtube网址输入接收的Wordpress网站(因为它显示在原始网站中),因此接收网站可以将其转换为预览(因为这些网站由我们控制) .

目前由内容生成的RSS源包含:

<content:encoded><![CDATA[<p><iframe width="525" height="295" src="https://https://www.www.youtube.com/embed/H51j54Z8yl8?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p></content:encoded>

但它应该是这样的(对吧?):

<content:encoded><![CDATA[<p>https://www.youtube.com/watch?v=H51j54Z8yl8</p></content:encoded>

问题1:如何使用preg_replace用空格替换第一部分(如果525宽度和295高度更改)?我可以使用“外卡”值吗?

function rss_noiframe($content) {
    $content = preg_replace( '<iframe width="525" height="295" src="', '', $content );

    return $content;
}

add_filter('the_excerpt_rss', 'rss_noiframe');
add_filter('the_content_feed', 'rss_noiframe');

问题2:如果我没有咆哮错误的树,我如何在上面的代码中创建一个额外的preg_replace:

替换第二部分:
"embed/"

附:
"watch?v="

并替换第3部分:
"?feature=oembed" frameborder = "0" allow = "accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>“

有:
“”?

问题3:哦,我在哪里放这个代码(我不是编码器) - 但是我希望有人制作一个插件来做这个,因为我对Child Themes等没有信心 .