【问题标题】:Adding parameters to vimeo videos via wordpress oembed通过 wordpress oembed 向 vimeo 视频添加参数
【发布时间】:2014-08-15 05:19:08
【问题描述】:

我正在尝试向通过 Wordpress 的 oembed 嵌入的 vimeo 视频添加参数。我已经使用下面的代码为 youtube 视频做到了这一点。我在functions.php中使用了这个函数,它就像一个魅力。我已经编辑了代码来为 Vimeo 视频做同样的事情,但我似乎无法让它工作。

这是我的代码:

function Oembed_vimeo_no_title($html,$url,$args){

// Only run this for vimeo embeds
if ( !strstr($url, 'vimeo.com') )
    return $html;

$url_string = parse_url($url, PHP_URL_QUERY);
parse_str($url_string, $id);
if (isset($id['v'])) {
    return '<div id="video_full_width"><iframe width="100%" height="394" src="//player.vimeo.com/video/'.$id['v'].'?title=0&amp;byline=0&amp;portrait=0" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen ></iframe></div>';
}
return $html;
}
add_filter('oembed_result','Oembed_vimeo_no_title',10,3);

关于我做错了什么有什么建议吗?

【问题讨论】:

    标签: wordpress function vimeo oembed


    【解决方案1】:

    我发现一个更好的方法是使用oembed_fetch_url 过滤钩子,就像这样:

    <?php
    /**
     * Add parameters to embed
     *
     * @src https://foxland.fi/adding-parameters-to-wordpress-oembed/
     * @src https://github.com/WordPress/WordPress/blob/ec417a34a7ce0d10a998b7eb6d50d7ba6291d94d/wp-includes/class-oembed.php#L553
     * @src https://developer.vimeo.com/api/oembed/videos
     *
     * Use it like this: `[embed autoplay="true"]https://vimeo.com/190063150[/embed]`
     */
    $allowed_args = ['autoplay'];
    
    function koa_oembed_args($provider, $url, $args) {
        global $allowed_args;
    
        $filtered_args = array_filter(
            $args,
            function ($key) use ($allowed_args) {
                return in_array($key, $allowed_args);
            },
            ARRAY_FILTER_USE_KEY
        );
    
        foreach ($filtered_args as $key => $value) {
            $provider = add_query_arg($key, $value, $provider);
        }
    
        return $provider;
    }
    
    add_filter('oembed_fetch_url', 'koa_oembed_args', 10, 3);
    

    我的其他答案中的更多详细信息:https://stackoverflow.com/a/55053642/799327

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 2021-11-14
      • 2016-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多