SEO & <meta>
tags
Search Engine Optimization is a dark art that some folks dedicate their entire lives to. We've add a couple of features to Redwood to make HTML-based SEO fairly simple.
Adding a Title
You certainly want to change the title of your Redwood app from the default of "Redwood App." You can start by adding or modifying title
inside of /redwood.toml
[web]
- title = "Redwood App"
+ title = "My Cool App"
port = 8910
apiUrl = "/.redwood/functions"
This title (the app title) is used by default for all your pages if you don't define another one. It will also be used for the title template.
Title Template
Now that you have the app title set, you probably want some consistence with the page title, that's what the title template is for.
Add titleTemplate
as a prop for RedwoodProvider
to have a title template for every page.
- <RedwoodProvider>
+ <RedwoodProvider titleTemplate="%PageTitle | %AppTitle">
/* ... */
<RedwoodProvider />
You can use whatever formatting you'd like in here. Some examples:
"%PageTitle | %AppTitle" => "Home Page | Redwood App"
"%AppTitle · %PageTitle" => "Redwood App · Home Page"
"%PageTitle : %AppTitle" => "Home Page : Redwood App"
Adding to Page <head>
So you want to change the title of your page, or add elements to the <head>
of the page? We've got you!
Let's say you want to change the title of your About page, Redwood provides a built-in <Head>
component, which you can use like this:
+import { Head } from '@cedarjs/web'
const AboutPage = () => {
return (
<div>
<h2>AboutPage</h2>
+ <Head>
+ <title>About the team</title>
+ </Head>
You can include any valid <head>
tag in here that you like. However, Redwood also provides a utility component <Metadata>.
<MetaTags>
DeprecationPrior to Redwood 6.6.0 this component was called <MetaTags>
and had several special hard-coded props like ogContentUrl
, which didn't properly map to the OpenGraph spec. We'll still render <MetaTags>
for the foreseeable future, but it's deprecated and you should migrate to <Metadata>
if you have an existing app.
What About Nested Tags?
Redwood uses react-helmet-async underneath, which will use the tags furthest down your component tree.
For example, if you set title in your Layout, and a title in your Page, it'll render the one in Page - this way you can override the tags you wish, while sharing the tags defined in Layout.
<meta>
TagsFor these headers to appear to bots and scrapers e.g. for twitter to show your title, you have to make sure your page is prerendered. If your content is static you can use Redwood's built-in Prerender. For dynamic tags, check the Dynamic head tags