Info
Inhalt

Arbeiten mit YouTube

Wenn Sie YouTube-Videos in Ihre Website einbetten, sollten Sie sicherstellen, dass diese ohne Einwilligung gesperrt werden.

Hinweis: Wir empfehlen, die "No-Cookie-Codes" von YouTube zu verwenden. Dazu einfach ersetzen www.youtube.com der <iframe ...> Code mit www.youtube-nocookie.com

Beispielcode vor Änderungen:

<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/gHTrl91Rdls" 
        frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" 
        allowfullscreen></iframe>

Beispielcode nach Änderungen:

<iframe data-cmp-vendor="s30" src="about:blank" class="cmplazyload" 
        width="560" height="315" 
        data-cmp-src="https://www.youtube-nocookie.com/embed/gHTrl91Rdls" frameborder="0" 
        allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" 
        allowfullscreen ></iframe>

Für YouTube-Videos, die größer als 300 x 300 Pixel sind, wird das CMP automatisch angewendet Blockierung dynamischer Inhalte.

YouTube-in Wordpress Webseiten

Um den YouTube-Einbettungscode in a anzupassen wordpress Website können Sie Folgendes verwenden WordPress-Code (fügen Sie ihn zur Functions.php Ihres hinzu WordPress Design-Theme), um alle YouTube-Videos auf Ihrer Website automatisch zu formatieren:

// customize wordpress gutenberg's core youtube block
function cmp_youtube_player($block_content, $block)
{
	if ("core/embed" === $block['blockName'] && "youtube" === $block['attrs']['providerNameSlug']) {
		$block_content = str_replace('?feature=oembed', '?feature=oembed&rel=0', $block_content);
		$block_content = str_replace(' src="https://www.youtube.com/', ' src="about:blank" data-cmp-src="https://www.youtube-nocookie.com/', $block_content);
        $block_content = str_replace(' src="https://www.youtube-nocookie.com/', ' src="about:blank" data-cmp-src="https://www.youtube-nocookie.com/', $block_content);
		$block_content = str_replace('<iframe ', '<iframe data-cmp-vendor="s30" class="cmplazyload" ', $block_content);
	}
	return $block_content;
}
add_filter('render_block', 'cmp_youtube_player', 10, 2);

Nach oben