diff --git a/Doc/conf.py b/Doc/conf.py
index 61c4e7d2b57fc8..9cb184d0786029 100644
--- a/Doc/conf.py
+++ b/Doc/conf.py
@@ -598,11 +598,17 @@
# Options for sphinxext-opengraph
# -------------------------------
-ogp_site_url = 'https://docs.python.org/3/'
+ogp_canonical_url = 'https://docs.python.org/3/'
ogp_site_name = 'Python documentation'
-ogp_image = '_static/og-image.png'
-ogp_custom_meta_tags = (
- '',
- '',
- '',
-)
+ogp_social_cards = { # Used when matplotlib is installed
+ 'image': '_static/og-image.png',
+ 'line_color': '#3776ab',
+}
+ogp_custom_meta_tags = ('',)
+if 'create-social-cards' not in tags: # noqa: F821
+ # Define a static preview image when not creating social cards
+ ogp_image = '_static/og-image.png'
+ ogp_custom_meta_tags += (
+ '',
+ '',
+ )