Last active
March 8, 2021 10:26
-
-
Save nicomollet/45aa0490cf29a3bc5267e456836dd34b to your computer and use it in GitHub Desktop.
WordPress: Add a "data-nosnippet" on oembed html (only for YouTube)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* oEmbed HTML: Adds a "data-nosnippet" on oembed html (only for YouTube) | |
* | |
* @param string|false $data The returned oEmbed HTML (false if unsafe). | |
* @param string $url URL of the content to be embedded. | |
* @param array $args Optional arguments, usually passed from a shortcode. | |
* | |
* @return string | |
*/ | |
function oembed_result_youtube_nosnippet( string $data, string $url, array $args ) { | |
if ( strpos( $url, 'youtube' ) !== false || strpos( $data, 'youtube' ) !== false ) { | |
$data = '<div data-nosnippet="true">' . $data . '</div>'; | |
} | |
return $data; | |
} | |
add_filter( 'oembed_result', 'oembed_result_youtube_nosnippet', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment