【问题标题】:Possible to add youtube title into Wordpress [embed][/embed]?可以将 youtube 标题添加到 Wordpress [嵌入] [/嵌入]?
【发布时间】:2016-08-30 11:06:29
【问题描述】:

我想弄清楚 Wordpress 上的 [embed][/embed] 短代码功能是否可以在 iframe 中显示标题?

当 youtube 视频显示在页面上后检查它时,它看起来像:

<iframe width="940" height="529" src="https://www.youtube.com/embed/xLZvgt_bPwE?feature=oembed" frameborder="0" allowfullscreen=""></iframe>

是否有一种方法可以编辑嵌入功能以包含标题(例如:&lt;iframe width="940" height="529" title="Youtube Video" src="https://www.youtube.com/embed/xLZvgt_bPwE?feature=oembed" frameborder="0" allowfullscreen=""&gt;&lt;/iframe&gt;,一旦它显示在页面或帖子上?

【问题讨论】:

    标签: wordpress iframe youtube shortcode


    【解决方案1】:

    如果您将此过滤器和函数添加到您的functions.php,它应该会提供您想要的结果:)

    function add_iframe_title($iframe){
        if($iframe)
        {
            $attributes = 'title="Embedded Video"';
            $iframe = str_replace('></iframe>', ' ' . $attributes . '></iframe>', $iframe);
    
            return $iframe;
        }
    
        return false;
    }
    
    add_filter('embed_oembed_html', 'my_embed_oembed_html', 99, 4);
    function my_embed_oembed_html($html, $url, $attr, $post_id) {
      if($html)
      {
        return add_iframe_title($html);
      }
      return false;
    }
    

    【讨论】:

    • 不知道为什么这没有被接受为答案。效果很好。
    猜你喜欢
    • 2018-04-08
    • 2016-11-24
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 2017-09-17
    • 2015-08-19
    相关资源
    最近更新 更多