将标题属性添加到嵌入式Wordpress嵌入式Youtube视频

时间:2019-04-26 00:31:43

标签: php wordpress filter genesis

我正在尝试将标题属性添加到通过Wordpress 5编辑器嵌入的youtube视频中。这是可访问性要求。

function add_title_to_iframe_oembed( $html, $url, $attributes, $post_id ) {

    // Bail if this isn't an iframe
    if ( strpos( $html, '<iframe' ) === false ) {
        return $html;
    }
    // Bail if the attributes already contain a title
    if ( array_key_exists( 'title', $attributes ) ) {
        return $html;
    }
    // Define the title for the iframe, depending on the source content
    // List is based on supported Video and Audio providers at https://codex.wordpress.org/Embeds
    $url = parse_url( $url );
    $title = '';
    switch ( str_replace( 'www.', '', $url['host'] ) ) {
        /**
         * Video
         */
        case 'animoto.com':
        case 'blip.com':
        case 'collegehumor.com':
        case 'dailymotion.com':
        case 'funnyordie.com':
        case 'hulu.com':
        case 'ted.com':
        case 'videopress.com':
        case 'vimeo.com':
        case 'vine.com':
        case 'wordpress.tv':
        case 'youtube.com':
            $title = __( 'Video Player', 'n7studios' );
            break;
        /**
         * Audio
         */
        case 'mixcloud.com':
        case 'reverbnation.com':
        case 'soundcloud.com':
        case 'spotify.com':
            $title = __( 'Audio Player', 'n7studios' );
            break;
        /**
         * Handle any other URLs here, via further code
         */
        default:
            $title = apply_filters( 'add_title_to_iframe_oembed', $title, $url );
            break;
    }
    // Add title to iframe, depending on the oembed provider
    $html = str_replace( '></iframe>', ' title="' . $title . '"></iframe>', $html );
    // Return

    //var_dump($html); exit;
    return $html;
}
add_filter( 'embed_oembed_html', 'add_title_to_iframe_oembed', 10, 4 );

我只能在var_dump html时看到标题。几乎就像另一个过滤器正在删除标题一样。

0 个答案:

没有答案