Google Not Showing React-Helmet Title And Description
Asked Answered
G

4

23

I'm using react-helmet to give each of my pages a unique title and description for my React application. The title is rendering correctly in the browser tab and the title and description are rendering correctly when I inspect the page using Dev Tools. However, Google isn't showing either the title or description in their search results. What am I doing wrong?

I've looked into using prerender.io but as my site doesn't have a backend (it's just a marketing site for the moment) I'm not sure it's a good solution. I've removed some elements, but this is essentially how my code looks...

import React, {Component} from 'react';
import {Helmet} from "react-helmet";

class Home extends Component {
  render() {
    return (
      <div>
        <Helmet>
          <title> My title </title>
          <meta name="description" content="My description"/>
        </Helmet>
      </div>
    )
  }
}

export default Home;
Glint answered 29/4, 2019 at 10:44 Comment(5)
hey @William, facing the same problem with my react website. Did you find a solution?Formica
Same here. I asked Google to re-crawl, but I don't know how long that takes. It's been 2 days and no change. Does anybody have insight?Suzansuzann
You can test a change to your crawl result by making a test page, informing google of the change via a new sitemap in the webmaster console. That will trigger a relatively immediate crawl for which you can see results that are untainted by previous attempts.Beckibeckie
Helmet won't as expected with CRA, check this out.Audacity
Hi @gael, I eventually moved to Next.js, which doesn't have this problem, so I can't give any recommendations to solve this issue with React alone I'm afraid. I hope you found a solution!Glint
L
6

I'm hosting a client side rendered React application and using react-helmet 5.2.1 to manage og tags and other sharing-related headers. I was running into the described issue with Facebook (and other websites), in that my sharing-related headers were not being recognized.

My React website is hosted using Netlify and the fix was to enable Netlify's Prerendering setting. After enabling Prerednering, sharing-related headers were immediately recognized. It seems headers rendered client-side are not recognized (more information from this SO question).

enter image description here

BTW, I found the Sharing Debugger offered by Facebook to be quite helpful when debugging issues with sharing-related headers.

Lobster answered 8/2, 2020 at 20:47 Comment(1)
Just turned mine on, it hasn't worked yet but hopefully it will soon (you mention it immediately worked so I'm a little worried mine isn't immediately working)Freewheeling
L
5

I am not sure if you have already figured out!

Try removing <meta name="description"> and <title> from public-> index.html folder.

Inject all <head> section using React Helmet directly to your js files. If your app.js is your landing page, try injecting all meta tags over there directly.

Also check your indexed page has data-react-helmet="true" in your meta tag, using Google Search console.

Request for re-indexing and wait for google to crawl again.

It's currently working for me in "react-helmet": "5.2.1"

Lament answered 3/1, 2020 at 8:45 Comment(0)
B
3

Although not specifically what you are asking for, you or others who may find this question may benefit from server side rendering. Even if you change up your react-helmet configuration, sites like Facebook will not cache your title and description when rendered via javascript.

Beckibeckie answered 1/2, 2020 at 15:46 Comment(0)
S
1

I had issues with my description tag which wasn't showing up correctly. Google instead displayed some random text from my post in the search result. Then I realized I didn't install the gatsby-plugin-react-helmet alongside the react-helmet package. So:

npm install gatsby-plugin-react-helmet react-helmet

And in your gatsby-config.js file, add the plugin. That solved my issues.

Sumner answered 21/12, 2020 at 20:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.