Sphinx extension to generate Open Graph metadata for each page of your documentation.
python -m pip install sphinxext-opengraph
sphinxext.opengraph to your extensions list in your
extensions = [ "sphinxext.opengraph", ]
These values are placed in the
conf.py of your Sphinx project.
Users hosting documentation on Read The Docs do not need to set any of the following unless custom configuration is wanted. The extension will automatically retrieve your site URL.
This config option is very important, set it to the URL the site is being hosted on.
Configure the amount of characters taken from a page. The default of 200 is probably good for most people. If something other than a number is used, it defaults back to 200.
This is not required. Name of the site. This is displayed above the title. Defaults to the Sphinx
projectconfig value. Set to
Falseto unset and use no default.
Configuration for automatically creating social media card PNGs for each page. For more information, see the social media cards docs.
This is not required. Link to image to show. Note that all relative paths are converted to be relative to the root of the html output as defined by
This is not required. Alt text for image. Defaults to using
ogp_site_nameor the document’s title as alt text, if available. Set to
Falseif you want to turn off alt text completely.
This is not required. Set to
Trueto use each page’s first image, if available. If set to
Truebut no image is found, Sphinx will use
This sets the ogp type attribute, for more information on the types available please take a look at https://ogp.me/#types. By default it is set to
website, which should be fine for most use cases.
This is not required. List of custom html snippets to insert.
This is not required. When
<meta name="description" content="...">from the page.
ogp_site_url = "http://example.org/" ogp_image = "http://example.org/image.png"
ogp_site_url = "http://example.org/" ogp_image = "http://example.org/image.png" ogp_description_length = 300 ogp_type = "article" ogp_custom_meta_tags = [ '<meta property="og:ignore_canonical" content="true" />', ] ogp_enable_meta_description = True
Per Page Overrides#
Field lists are used to allow you to override certain settings on each page and set unsupported arbitrary Open Graph tags.
Make sure you place the fields at the very start of the document such that Sphinx will pick them up and also won’t build them into the html.
These are some overrides that can be used on individual pages, you can actually override any tag and field lists will always take priority.
Configure the amount of characters to grab for the description of the page. If the value isn’t a number it will fall back to
Disables generation of Open Graph tags on the page.
Lets you override the description of the page.
.. meta::\n :description:
<meta name="description" content="...">description.
Lets you override the title of the page.
Override the type of the page, for the list of available types take a look at https://ogp.me/#types.
Set the image for the page.
Sets the alt text. Will be ignored if there is no image set.
Remember that the fields must be placed at the very start of the file. You can verify Sphinx has picked up the fields if they aren’t shown in the final html file.
:og:description: New description :og:image: http://example.org/image.png :og:image:alt: Example Image Page contents =============