Skip to content

Customize page title per plugin instance - avoid duplicated page title #5878

Closed

Description

@greenpau

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

By default, the landing page name repeats itself, i.e. "Auth with Caddy | Auth with Caddy".

image

Steps to reproduce

Please see the landing page of https://authp.github.io/

Expected behavior

The page name should not repeat, i.e. be "Auth with Caddy".

Actual behavior

The name repeats itself "Auth with Caddy | Auth with Caddy".

image

Your environment

Reproducible demo

No response

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on Nov 4, 2021
  2. Josh-Cena commented on Nov 4, 2021

    @Josh-Cena
    Collaborator

    You can omit the title field in the home page layout:

    export default function home() {
      return (
        // Don't add the title here
        <Layout>
          {/* ... */}
        <Layout>
      )
    }

    And I do think there's something we can do: check if site title is equal to page title, and do not duplicate if that's the case:

    https://github.com/facebook/docusaurus/blob/cbcaa52f88cb702a3712c2b4c19b02225f975ea9/packages/docusaurus-theme-common/src/utils/generalUtils.ts#L12-L14

  3. removed
    status: needs triage
    on Nov 4, 2021
  4. greenpau commented on Nov 4, 2021

    @greenpau
    Author

    You can omit the title field in the home page layout:

    @Josh-Cena , thank you! This change from defaults worked! 👍

    And I do think there's something we can do: check if site title is equal to page title, and do not duplicate if that's the case:

    Yes, that would be great!

    Additionally, it would be nice to have "Page Name" | "Instance Name" | "Site Title" in the case of multi-doc instance.

    For example, I have two pages:

    Path Page Name
    https://authp.github.io/docs/authenticate/intro Auth Portal Plugin Overview | Auth with Caddy
    https://authp.github.io/docs/authorize/intro Authorize Plugin Overview | Auth with Caddy

    It would be nice to have instance name (i.e. Authenticate and Authorize) taken into account.

    Path Page Name
    https://authp.github.io/docs/authenticate/intro Auth Portal Plugin Overview | Authenticate | Auth with Caddy
    https://authp.github.io/docs/authorize/intro Authorize Plugin Overview | Authorize | Auth with Caddy
  5. Josh-Cena commented on Nov 7, 2021

    @Josh-Cena
    Collaborator

    I propose this API to replace the current titleDelimiter in docusaurus.config.js:

    titleFormat: '{pageTitle} | {pluginID} | {siteTitle}'
    

    It will leverage the existing interpolate API, and you can swap out the delimiter, rearrange the components, get rid of siteTitle on all pages, etc.

    Afaik, every page belongs to a plugin, so the pluginID will always be available. When pluginID === 'default', it will be omitted.

  6. greenpau commented on Nov 7, 2021

    @greenpau
    Author

    @Josh-Cena , what about adding pluginTitle field?

  7. Josh-Cena commented on Nov 7, 2021

    @Josh-Cena
    Collaborator

    You mean... allowing each plugin instance to declare its own title component instead of relying on pluginID? That sounds fine with me

  8. slorber commented on Nov 9, 2021

    @slorber
    Collaborator

    Using plugin instance name in site title is a quite specific need.

    In any case, I'd rather not apply this by default, and I think it's more a theming concern, not sure we want to add a nodejs plugin option just for this.

    React Helmet already has a titleTemplate system so it's worth reusing it (already in use) instead of using our custom interpolate fn.

    The way I'd solve it:

    • swizzle/wrap the theme DocPage component (we should rename it to something better like DocLayout, and IMHO each plugin should always have a layout comp with a consistent name)
    • add <Head titleTemplate={currentInstanceId === "ios" ? "%s | iOS | MySite" : "%s | Android | MySite"}/> in it

    Didn't test this but it should work. I'd rather use this because this is a marginal use-case and we already have/want APIs to support that

  9. slorber commented on Nov 9, 2021

    @slorber
    Collaborator

    Oh actually didn't even notice but we don't use titleTemplate but rather a custom useTitleFormatter hook 😅

    titleFormat: '{pageTitle} | {pluginID} | {siteTitle}'

    This is not a bad idea to have such a global themeConfig but the pluginId is not necessarily a good-looking label, and we can't easily make it good looking because it's used in many places like FS paths, not allowing all kind of chars.

  10. changed the title [-]landing/home page name repeats itself[/-] [+]Customize page title per plugin instance[/+] on Nov 9, 2021
  11. added
    feature
    and removed
    bug
    on Jan 31, 2022
  12. slorber commented on May 26, 2022

    @slorber
    Collaborator

    Relevant discussions related to customizing site title (in particular the prefix)

    #6640
    #7491

  13. elitan commented on May 31, 2022

    @elitan

    Another one: #7535

  14. added
    bug
    on Aug 16, 2022
  15. changed the title [-]Customize page title per plugin instance[/-] [+]Customize page title per plugin instance - avoid duplicated page title[/+] on Aug 16, 2022
  16. anaclumos commented on Sep 14, 2022

    @anaclumos
    Contributor

    Would like to hear any updates on this!

  17. Sas2k commented on Sep 30, 2022

    @Sas2k

    yeah same here (Not to NecroPost)

  18. laureladastra commented on Jan 25, 2023

    @laureladastra

    Upvoted. Not entirely sure what the rationale was behind the decision to create these SEO values dynamically. You want to have full control as a website owner over this aspect.

  19. jetxr commented on Jul 1, 2023

    @jetxr

    I propose this API to replace the current titleDelimiter in docusaurus.config.js:

    titleFormat: '{pageTitle} | {pluginID} | {siteTitle}'
    

    It will leverage the existing interpolate API, and you can swap out the delimiter, rearrange the components, get rid of siteTitle on all pages, etc.

    This would be superb. Would help to avoid swizzling layouts just to change the title format.

  20. slorber commented on Apr 11, 2025

    @slorber
    Collaborator

    The use-case will be solved by #11090 in v3.8

    For now, the API is not perfect, but it is the most flexible: you will need to swizzle a small theme component, which makes it possible to provide your own code logic instead of dealing with a static string template.

    We may provide a siteConfig option later.

    I'd also like to collect feedback before implementing a new public siteConfig API. For example: are the provided callback params enough to solve most use cases?

    Maybe we'll also want to deprecate siteConfig.titleDelimiter later if we have a more powerful API.


    In the future, we'll likely implement an API to assign a "label" to a plugin instance. For example, you may have 2 docs plugin instance (iOS + Android). Plugin ids are used for file system paths, and are not meant to be displayed in meta title. So a plugin instance label would look cleaner to display in a title.

    We also need this for docs breadcrumbs, where we'd want a breadcrumb such as Home > iOS > My iOS doc page, see related issues:

  21. jtbandes commented on May 16, 2025

    @jtbandes

    #11090 is a nice feature, but it seems the <title> and <meta name="og:title"> are still required to be the same. Would it be possible to make these different? For example, it's common for sites to specify og:title + og:site_name metadata separately, and then use <title>{title} | {siteName}</title> for the traditional title.

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

    bugfeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions