如何为网站Meta标签添加YouTube视频及将Facebook视频配置至og:video Meta标签(含Google合规要求解决方案)
Hey there! Let's tackle your questions one by one to get everything sorted out for you:
If you want social platforms (like Facebook or Twitter) to show a YouTube video preview when your site is shared, or help search engines recognize the video content, you’ll want to use Open Graph (OG) meta tags. Here’s the standard setup:
- Grab your YouTube video ID (it’s the string after
watch?v=in the video URL, e.g.,abc123fromhttps://www.youtube.com/watch?v=abc123). - Add these OG tags to your
<head>section:
The embed URL (<meta property="og:video" content="https://www.youtube.com/embed/abc123"> <meta property="og:video:type" content="text/html"> <meta property="og:video:width" content="1280"> <meta property="og:video:height" content="720">youtube.com/embed/[ID]) is preferred here because it’s optimized for platform crawlers to fetch and display the video preview.
og:video Meta Tag For Facebook-hosted videos, the process is similar but uses Facebook’s embed URL instead:
- Go to your Facebook video page, click the "Embed" button, and copy the
srcvalue from the generated iframe code (it’ll look likehttps://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2F[PAGE_NAME]%2Fvideos%2F[VIDEO_ID]%2F). - Add these OG tags to your
<head>:
<meta property="og:video" content="https://www.facebook.com/plugins/video.php?href=https%3A%2F%2Fwww.facebook.com%2F[PAGE_NAME]%2Fvideos%2F[VIDEO_ID]%2F"> <meta property="og:video:type" content="text/html"> <meta property="og:video:width" content="560"> <meta property="og:video:height" content="315">
Make sure your Facebook video is set to public—otherwise, crawlers won’t be able to access it to generate previews.
You’re spot-on about that Google rule: never put <iframe> or <img> tags inside your <head> section. Here’s the official context you referenced:
HTML规范规定,head标签中仅允许包含上述提及的元素,其余元素均为无效元素。常见的会导致head标签失效的元素包括:iframe、img。我们强烈建议不要在head标签中使用这些无效元素;若必须使用,请将这些无效元素放置在希望Google抓取的元素之后。一旦Google检测到此类无效元素,会判定head标签结束,停止读取后续的head元素。
If you need to embed a video on your page, always put the <iframe> in the <body> section (where your page content lives). Putting it in the <head> doesn’t help search engines recognize the video anyway—they use meta tags and structured data for that, not misplaced iframes.
To make your site show a video preview next to its search listing, you need to meet a few key requirements:
- Add Schema.org structured data: Use the
VideoObjecttype to tell Google all the important details about your video. Here’s a sample:
If you’re using a YouTube/Facebook embed, use that embed URL for<script type="application/ld+json"> { "@context": "https://schema.org", "@type": "VideoObject", "name": "Your Video’s Clear, Descriptive Title", "description": "A detailed summary of what your video covers", "thumbnailUrl": "https://your-site.com/video-thumbnail.jpg", "uploadDate": "2024-05-20T12:00:00Z", "duration": "PT15M30S", "embedUrl": "https://your-site.com/embed-your-video.html" } </script>embedUrl. - Ensure crawlability: Your video page must be public (no login walls), and your robots.txt file shouldn’t block search crawlers from accessing it.
- Use high-quality thumbnails: Aim for at least 1200x675 pixels with a 16:9 aspect ratio—this helps Google display a crisp preview.
- Match content to video: Your page’s text content should directly relate to the video’s topic. Google won’t show a video preview if the page and video don’t align.
- Follow content policies: Make sure your video doesn’t violate copyright or Google’s content guidelines.
You can use Google’s Rich Results Test tool to check if your structured data is set up correctly—this will flag any errors that might prevent the video preview from showing up.
内容的提问来源于stack exchange,提问作者Al Martins

