How can Open Graph declare a custom object type?

The Citead team, updated

In short. Declare a namespace prefix and use its colon-separated name in the Open Graph og:type value.

Definition: Open Graph declares a custom object type by putting a CURIE in og:type, such as my_namespace:my_type, and mapping my_namespace to a namespace URI in a prefix attribute. The protocol reserves bare names and period-separated names for its documented global types.

Key facts

  • The Open Graph protocol uses og:type to specify the type of the object represented in the graph, and lists it among the four required properties for every page in its basic metadata section.
  • A community-agreed schema becomes a global type in the protocol's type system, according to the Open Graph protocol specification.
  • A custom type uses the CURIE form prefix:name; the prefix is declared with a namespace URI, as in my_namespace: https://example.com/ns#.
  • Open Graph groups global types into verticals, such as music and video, and documents names such as music.song.
  • The W3C RDFa 1.1 Primer explains that prefix:reference expands to a full URL by concatenating the URL assigned to the prefix with the reference.

What is the difference between a global and a custom type?

The Open Graph specification says that a type enters the list of global types when the community agrees on its schema. A global type is therefore written using the name documented by the protocol, such as website, article, or video.movie. The specification groups global types into verticals, and says that each vertical has its own namespace.

The naming rule is visible in the specification's examples. A global type in a namespace uses the namespace name followed by a period, as in music.song or video.movie. A user-defined namespaced type uses a colon, as in my_namespace:my_type. The punctuation is part of the documented distinction between the protocol's global names and custom names.

How do you declare the custom namespace?

Declare the prefix on the head element or another HTML element that contains the Open Graph metadata. The Open Graph example uses a namespace URI ending in # and then uses the declared prefix in the og:type content value:

<head prefix="my_namespace: https://example.com/ns#">
<meta property="og:type" content="my_namespace:my_type" />
</head>

The W3C primer describes this as RDFa prefixed-term syntax. Its rule is that the URL associated with a prefix is concatenated to the reference after the colon to create the full URL. The prefix declaration applies to the elements below it, so the declaration needs to cover the meta element carrying the custom type.

For the Open Graph vocabulary itself, the protocol's page declares og with https://ogp.me/ns#. A basic page can therefore use og:type alongside og:title, og:image, and og:url:

<html prefix="og: https://ogp.me/ns#">
<meta property="og:type" content="video.movie" />
</html>

What should the og:type value contain?

Use a documented global name when the object matches one of the protocol's global types. The specification gives website as a global value and video.movie as a vertical value. The same page states that the type can make other properties required, so the selected type affects which additional Open Graph properties belong with the object.

Use a prefixed custom name when the type belongs to a vocabulary outside the protocol's global list. The custom example supplies both parts: my_namespace identifies the namespace declaration, and my_type identifies the term within that namespace. W3C's RDFa documentation also says that a custom vocabulary can define classes and properties at a selected vocabulary URL and then be used in RDFa markup.

FAQ

Can a custom type use a period like video.movie?

The Open Graph specification uses period-separated names for global types grouped in its namespaces. Its custom example uses the colon form my_namespace:my_type, so a custom declaration should follow that documented form.

Does og:type name the namespace itself?

No. The prefix attribute maps a short prefix to a namespace URI, while the og:type content value supplies the type name. The W3C primer describes the resulting expansion as the prefix URL concatenated with the reference.

Is og the same as a custom prefix?

og is the prefix used for the Open Graph vocabulary and is mapped to https://ogp.me/ns# in the protocol's example. A custom type uses a separate prefix mapped to the URI of its own vocabulary.

Sources

  1. Open Graph protocol, "The Open Graph protocol", undated
  2. W3C, "RDFa 1.1 Primer - Third Edition", 17 March 2015

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark