Skip to content

Add meta tags to docs.python.org #65

Description

@Mariatta

We need to add <meta> tags to the output of sphinx documentation.

It looks like this is supported using the meta directive

https://docutils.sourceforge.io/docs/ref/rst/directives.html#meta

Example:

.. meta::
   :description: The reStructuredText plaintext markup language
   :keywords: plaintext, markup language

Some meta tags we should have:

  • title
  • description

Some advice according to: https://ahrefs.com/blog/seo-meta-tags/

Title meta:

  • Write a unique title tag for each page;
  • Be brief, but descriptive;
  • Avoid generic and vague titles;
  • Use sentence case or title case;
  • Create something click-worthy—not clickbait;
  • Match search intent;
  • Include your target keyword where it makes sense;
  • Keep it under 60 characters.

Description meta:

  • Write a unique description for each page;
  • Try to summarize content accurately;
  • Avoid generic descriptions;
  • Use sentence case;
  • Create something click-worthy, not clickbait;
  • Match search intent;
  • Include your target keyword where it makes sense;
  • Keep it under 160 characters

Activity

  1. Mariatta commented on Oct 5, 2022

    @Mariatta
    MemberAuthor

    I think this is where we could get expert advice on what to write inside the title and description meta tags.

  2. ezio-melotti commented on Oct 6, 2022

    @ezio-melotti
    Member

    I don't think we should add them manually, but use an extension to automate the creation instead.

    sphinxext-opengraph already does this for OGP meta tags (including automatically setting the title and description), but apparently not for regular meta tags. I haven't checked yet if there are other extensions that can add those, if not, we can create one similar to sphinxext-opengraph or make a PR against it to add this feature (if they are interested).

    See also:

  3. hugovk commented on Oct 6, 2022

    @hugovk
    Member

    sphinxext-opengraph already does this for OGP meta tags (including automatically setting the title and description), but apparently not for regular meta tags. I haven't checked yet if there are other extensions that can add those, if not, we can create one similar to sphinxext-opengraph or make a PR against it to add this feature (if they are interested).

    They're interested, there's a feature request to add <meta name="description">: sphinx-doc/sphinxext-opengraph#65).

  4. Mariatta commented on Oct 6, 2022

    @Mariatta
    MemberAuthor

    The extension looks interesting. Looking at the comments, it seems like we can probably use the ogp_custom_meta_tags?

  5. hugovk commented on Oct 18, 2022

    @hugovk
    Member

    We can't use ogp_custom_meta_tags because they would be hardcoded for all pages, and we'd like them generated for each page.

    They're interested, there's a feature request to add <meta name="description">: wpilibsuite/sphinxext-opengraph#65).

    I've created a PR for this: sphinx-doc/sphinxext-opengraph#71.

  6. hugovk commented on Aug 4, 2023

    @hugovk
    Member

    Description meta tags have now been added by python/cpython#99931.

    For example, https://docs.python.org/3/library/sys_path_init.html has:

    <meta property="og:title" content="The initialization of the sys.path module search path" />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="https://docs.python.org/3/library/sys_path_init.html" />
    <meta property="og:site_name" content="Python documentation" />
    <meta property="og:description" content="A module search path is initialized when Python starts. This module search path may be accessed at sys.path. The first entry in the module search path is the directory that contains the input scrip..." />
    <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
    <meta property="og:image:alt" content="Python documentation" />
    <meta name="description" content="A module search path is initialized when Python starts. This module search path may be accessed at sys.path. The first entry in the module search path is the directory that contains the input scrip..." />
    <meta property="og:image:width" content="200" />
    <meta property="og:image:height" content="200" />

    See also #63 (comment).

  7. StanFromIreland commented on Feb 24, 2025

    @StanFromIreland
    Member

    The auto generation is not the best:

    Image

    Maybe this should be revisited? Adding them manually for key pages?

  8. hugovk commented on Feb 24, 2025

    @hugovk
    Member

    The frontpage itself is a template page, and therefore sphinxext-opengraph doesn't generate tags for it.

    So yes, we should manually add tags for that page. Would you like to open a new issue for it?

    For comparison, here's one that is generated:

    Image
  9. StanFromIreland commented on Feb 24, 2025

    @StanFromIreland
    Member

    Where to open it? Here or cpython? I can push a pr with the tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions