Arbeiten mit YouTube

Wenn Sie YouTube-Videos in Ihre Website einbetten, sollten Sie sicherstellen, dass diese blockiert werden, wenn keine Einwilligung vorliegt.

Hinweis: Wir empfehlen die Verwendung der „No-Cookie-Codes“ von YouTube. Dazu ersetzen Sie einfach www.youtube.com im <iframe ...> Code durch www.youtube-nocookie.com

Beispielcode vor den Ä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 den Ä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>

Bei YouTube-Videos, die größer als 300 x 300 Pixel sind, wendet das CMP automatisch eine dynamische Inhaltsblockierung an.

YouTube auf WordPress-Websites

Um den YouTube-Einbettungscode in einer WordPress-Website anzupassen, kannst du den folgenden WordPress-Code verwenden (füge ihn in die Datei functions.php deines WordPress-Design-Themes ein), um alle YouTube-Videos auf deiner 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);

We do our best to keep this purely informative documentation up to date. However, if you notice that any of these guides need a little touch-up, let us know!