Skip to content

How to get the document title using id? #7133

Answered by slorber
dninomiya asked this question in Q&A
Discussion options

You must be logged in to vote

You might find these 2 hooks useful.

import {useDocsVersion,useDocById} from '@docusaurus/theme-common';

useDocById("xyz").title

useDocsVersion().docs.find(doc => doc.title = "XYZ title").id

But keep in mind they are for now internal APIs that we might do breaking changes on (altough it's unlikely the feature will totally disappear), so only use this wisely in your site code (ie avoid publishing an open-source plugin using those)

Note: these hooks will only work on components rendered on docs page (ie not on your homepage or blog posts). One id can be used in multiple docs versions so you have to be browsing a specific version for Docusaurus to know which to return.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@dninomiya
Comment options

@dninomiya
Comment options

@slorber
Comment options

@mellson
Comment options

Answer selected by slorber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants