Integrate YouTube into WordPress without cookies in accordance with GDPR

Embed YouTube videos in Wordpress without cookies

Although I produce very little for YouTube myself, I find other people's videos very helpful. Even with Mac or iPhone problems, a video is sometimes more descriptive than writing a lot of words. Incidentally, that also shows that macOS Catalina book by Anton Ochsenkühn, which relies on many explanatory videos and thus makes macOS functions much clearer than many books that only consist of a text mess with isolated screenshots.

If you now embed YouTube videos in your WordPress blog by just copying the video URL into the text, WordPress replaces this with an iframe embed code during output, which unfortunately leads to cookies from YouTube being stored in the browser of the Set by the user. However, given the current EU cookie situation, this is legally critical and should be avoided.

Embed YouTube videos in WordPress without cookies

In this post I show how you can embed YouTube videos in WordPress without cookies. This also works for free with a change in a WordPress file.

Difference between cookies and tracking

It is important to know that turning off cookies does not mean that YouTube can collect data about the user. Even if you use the nocookie variant of the embedding code from YouTube, by including the video in your own blog it is still possible for YouTube to collect information about the article the moment the user calls up the article. The safe way to prevent this is the Borlabs Cookie Plugin, which I will mention shortly. This requires user approval before the embed code is run.

Note: I am not a lawyer and this is also not legal advice. ;-)

Alternative 1: Borlabs Cookie Plugin

I chose the paid solution on my blog and I chose the Borlabs cookie plugin for WordPress installed and configured. The plug-in requires user approval before the videos can be played. At 39 euros per year, the service is okay for me, as I also earn money with my blog, but if you have little financial means and only maintain an informative blog that does not generate anything, then the second alternative may be the right choice.

In the Borlabs Cookie plug-in, cookies can be prevented with one click. After that, the user must first accept the cookies before the video can be played (screenshots: Sir Apfelot).

In the Borlabs Cookie plug-in, cookies can be prevented with one click. After that, the user must first accept the cookies before the video can be played (screenshots: Sir Apfelot).

On the other hand, those who use Google Analytics and other cookie-friendly services should perhaps consider whether investing in Borlabs Cookie is a good idea. With the plugin, many services are already preconfigured and only need to be activated. This is much easier than integrating them in a dsgvo-compliant way via detours.

Alternative 2: change Youtube embed code

For years, YouTube has had an option to prevent cookies from being set when calling up the embedding code for a video. Unfortunately, WordPress does not use this option by default and instead always uses the YouTube code, which uses cookies. I hope this will be changed in the core of WordPress soon, but currently you have to take care of it yourself.

If you want to create the embed code for a video, you can activate the "Extended data protection mode" in the options.

If you create the embed code for a video, you can activate the "Extended data protection mode" in the options to prevent cookies from being set.

If you want to stop WordPress from doing this, you need to intervene in the funktions.php file, which can be found in every theme directory of a WordPress installation. The path is this one:

/WORDPRESS/wp-content/themes/NAME-DES-THEMES/functions.php

You open this file (or create it if it does not yet exist) and add the following code (I found the code somewhere, but unfortunately I did not note the source):

add_filter ('embed_oembed_html', 'youtube_nocookie_loesung', 10, 4); function youtube_nocookie_solution ($ original, $ url, $ attr, $ post_ID) {$ html = str_replace ("youtube.com", "youtube-nocookie.com", $ original); $ html = str_replace ("feature = oembed", "feature = oembed & showinfo = 0", $ html); return $ html; }

If there was already code in functions.php, you can add it below. If the file is still empty, you have to add "

After inserting the code, the YouTube URLs will be replaced by the domain "youtube-nocookie.com", which does not set any cookies.

In the embed code you can see that the domain will be changed after activating the data protection mode.

In the embed code you can see that the domain will be changed after activating the data protection mode.

Important: Change your own iFrame codes manually!

Anyone who has used the YouTube embed code in the source text of the blog article here and there should change it manually and switch to the youtube-nocookie.com domain. The script mentioned above does not change their occurrence, but only intervenes if the pure URL to the YouTube video has been incorporated into the posts.

Tip: change functions.php with plugin

If tinkering with the PHP file is too dangerous for you, you can also use the plugin "Code Snippets"Install, which allows you to smuggle arbitrary code into WordPress, as the functions.php would do - except that the code is saved in the database and is not lost after a theme update. I would prefer this way as a beginner .

 

-
Do you like my blog? Then I would be happy to receive a short review on Google. Easy leave something here for a moment - that would be great, thank you!

 

Effectively for free: iPhone 13 Mini and iPhone 13 deals with top conditions at Otelo - Advertisement

Leave a Comment

Your e-mail address will not be published. Required fields are marked with * .