doupike2351 2015-09-28 15:38
浏览 77

wordpress php更改视频的oembed代码

As most people know, wordpress uses oembed to fetch the embed code for videos when adding a youtube video to a post. For example, pasting:

https://www.youtube.com/watch?v=pATcvr3zAhg

Would output this in the html:

<iframe width="420" height="315" src="https://www.youtube.com/embed/pATcvr3zAhg" frameborder="0" allowfullscreen></iframe>

I want to change this markup so it uses fancybox and an image, so my markup should look like this:

<a class="fancybox.iframe various" href="VIDEO SOURCE"><img src="IMAGE HERE"></a>

I was using this code which originally replaced the video with an image and when clicked, changed to the video - however, I want to modify this code now so that it outputs the markup above.

add_filter( 'oembed_dataparse', function($str, $data, $url) {

if ( ($yt = $data->provider_name == 'YouTube') || ($vm = $data->provider_name == 'Vimeo') ) 
{
    if($yt) $html = str_replace('feature=oembed', 'feature=oembed&autoplay=1', $str);
    else $html = str_replace('" width=', '?autoplay=1" width=', $str);

    $html = htmlentities($html, ENT_QUOTES);
    $img = $data->thumbnail_url; 
    $title = esc_attr($data->title);

    return '<img src="'. $img . '" onclick="this.outerHTML=\'' . $html . '\'" title="' . $title . '">';
}

return $str;

}, 10, 3);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于这个问题的解释说明
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败
    • ¥20 java在应用程序里获取不到扬声器设备
    • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。