The embed_googlevideo WordPress PHP filter allows you to modify the Google Video embed output in WordPress.
Usage
add_filter('embed_googlevideo', 'your_custom_function', 10, 5);
function your_custom_function($html, $matches, $attr, $url, $rawattr) {
// your custom code here
return $html;
}
Parameters
- $html (string): Google Video HTML embed markup.
- $matches (array): The RegEx matches from the provided regex.
- $attr (array): An array of embed attributes.
- $url (string): The original URL that was matched by the regex.
- $rawattr (array): The original unmodified attributes.
More information
See WordPress Developer Resources: embed_googlevideo
Examples
Change the video player width and height
Modify the width and height of the Google Video player.
add_filter('embed_googlevideo', 'change_video_size', 10, 5);
function change_video_size($html, $matches, $attr, $url, $rawattr) {
$new_width = 640;
$new_height = 360;
$html = str_replace("width='480'", "width='{$new_width}'", $html);
$html = str_replace("height='385'", "height='{$new_height}'", $html);
return $html;
}
Add custom CSS class to the video iframe
Add a custom CSS class to the Google Video iframe.
add_filter('embed_googlevideo', 'add_custom_css_class', 10, 5);
function add_custom_css_class($html, $matches, $attr, $url, $rawattr) {
$html = str_replace('<iframe ', '<iframe class="your-custom-class" ', $html);
return $html;
}
Remove frameborder attribute
Remove the frameborder attribute from the Google Video iframe.
add_filter('embed_googlevideo', 'remove_frameborder', 10, 5);
function remove_frameborder($html, $matches, $attr, $url, $rawattr) {
$html = str_replace("frameborder='0'", "", $html);
return $html;
}
Add a custom wrapper around the video iframe
Wrap the Google Video iframe in a custom div.
add_filter('embed_googlevideo', 'add_custom_wrapper', 10, 5);
function add_custom_wrapper($html, $matches, $attr, $url, $rawattr) {
$html = '<div class="your-custom-wrapper">' . $html . '</div>';
return $html;
}
Replace the video embed with a custom message
Display a custom message instead of embedding the Google Video.
add_filter('embed_googlevideo', 'replace_video_with_message', 10, 5);
function replace_video_with_message($html, $matches, $attr, $url, $rawattr) {
$html = '<p>Google Video is no longer supported. Please visit <a href="' . $url . '">the original video</a> directly.</p>';
return $html;
}