Skip to content

announcementBar on homepage only #10075

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

You must be logged in to vote

You can swizzle the @theme/AnnouncementBar component and make it render null/false when it's not on the homepage.

const {pathname} = useLocation()
const isHomePage = pathname === "/"
if (!isHomePage) {
  return null;
}

Or you can swizzle @theme/Layout, add a prop such as noAnnouncementBar={true} to hide it conditionally, or using the location pathname like above.

You can also hide it with CSS, although it will remain in the DOM tree on pages that don't need it.

As you can see, you have many options to do that 😄

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@peterpeterparker
Comment options

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