Should og:image and og:url put in <meta> or <link>?

后端 未结 2 532
忘了有多久
忘了有多久 2021-01-23 05:31

For og:image and og:url, since they have URL, can I place them in a link tag instead of a meta tag, and is it preferable?

相关标签:
2条回答
  • 2021-01-23 05:34

    I don't know about other major consumers of the OGP so this might not be a problem for your case, but if you plan to implement it for Facebook,

    stick to meta tags.

    Doing a quick live test with the open graph debugger and fiddling with the og: tags, it appears that facebook only recognizes them if they are placed in <meta>s.

    Try it

    If you create an empty HTML file with a single og:url tag in its <head> section, upload it to any URL and run it through the debugger above, both

    <link rel="og:url" href="http://www.imdb.com/title/tt0117500/" />
    

    and

    <link property="og:url" content="http://www.imdb.com/title/tt0117500/" />
    

    edit or, as suggested in the comments

    <link property="og:url" href="http://www.imdb.com/title/tt0117500/" />
    

    will fail to parse and return the original URL, while

    <meta property="og:url" content="http://www.imdb.com/title/tt0117500/" /> 
    

    parses correctly and returns the contents of The Rock on IMDb instead. At the end of the day semantics are nice, but working code is even better.

    0 讨论(0)
  • 2021-01-23 05:59

    You must use link instead of meta if the value is a URL.

    From the definition of the meta element:

    The meta element represents various kinds of metadata that cannot be expressed using the […] link […] elements.

    But a URL can of course be expressed using a link element (as it’s its purpose).

    If you use a meta element for a URL value, RDFa parsers would extract a string value instead of a URL value. This also means that they wouldn’t be able to apply relative references against the base URL.

    Example

    Let’s say these elements are in a document with the URL http://example.com/foo:

    <link property="schema:url"    href="/bar" />
    <meta property="schema:url" content="/bar" />
    

    The value from the link element is the URL http://example.com/bar.
    The value from the meta element is the string /bar.

    However, in the case of OGP …

    The examples in OGP’s documentation use the meta element for URL values; there is no example with a link element.

    While this means that many of their examples are invalid HTML+RDFa, and RDFa parsers will extract strings instead of URLs in those cases,
    it may be the case that Facebook (or any other consumer) isn’t actually using RDFa to parse the content, and it may be the case that they don’t support link elements.

    Note: These are just possibilities, judging from the quality of their documentation. I don’t have any experience/insight, as I don’t use Facebook. So you might want to test it with Facebook if you care about their OGP-based features.

    0 讨论(0)
提交回复
热议问题