You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Gutenberg编辑器YouTube嵌入块的「Watch on Youtube」栏

解决Gutenberg编辑器YouTube嵌入块无法添加参数隐藏「Watch on YouTube」栏的问题

方法一:使用自定义HTML块(适合非开发者)

  • 打开目标YouTube视频页面,点击「分享」→「嵌入」,复制生成的iframe代码
  • 在代码的src属性末尾添加参数 &modestbranding=1,示例修改前后对比:
    原代码:
    <iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    
    修改后:
    <iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID?modestbranding=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    
  • 在Gutenberg编辑器中添加「自定义HTML」块,粘贴修改后的代码即可

方法二:通过代码自动添加参数(适合开发者)

如果想继续使用原生YouTube嵌入块,无需手动修改代码,可在主题的functions.php文件中添加以下代码片段:

add_filter('embed_oembed_html', 'add_youtube_modest_branding', 10, 3);
function add_youtube_modest_branding($html, $url, $args) {
    // 检测是否为YouTube链接
    if (strpos($url, 'youtube.com') !== false || strpos($url, 'youtu.be') !== false) {
        // 转换youtu.be短链接为标准格式
        if (strpos($url, 'youtu.be') !== false) {
            $video_id = ltrim(parse_url($url, PHP_URL_PATH), '/');
            $url = "https://www.youtube.com/watch?v={$video_id}";
        }
        // 自动添加modestbranding参数
        $url = add_query_arg('modestbranding', '1', $url);
        // 重新生成嵌入HTML
        $html = wp_oembed_get($url);
    }
    return $html;
}

这段代码会自动给所有Gutenberg嵌入的YouTube视频添加modestbranding=1参数,原生块就能直接隐藏「Watch on YouTube」栏。

注:modestbranding=1是YouTube官方支持的嵌入参数,作用是隐藏视频左下角的品牌标识栏及跳转链接,仅保留基础播放控件。

内容的提问来源于stack exchange,提问作者Giovanna Penna Eirada

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 20:22:21