Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to change meta tags dynamically while page is loading and after that share it to some socials? #218

Open
Lenur29 opened this issue Mar 14, 2024 · 2 comments

Comments

@Lenur29
Copy link

Lenur29 commented Mar 14, 2024

Hi @staylor. I need your help if it is possible

Here is the case. In my React(SPA) application I have only one page that needs to be shared. And when it is shared I need to add the following meta tags to the head element:

<head>
  <meta name="description" content="some text" />
  <meta property="og:image" content="../../some-ing.png" />
  <meta property="og:description" content="some text"  />
</head>

It changes meta tags when the page mounts if I check it in the developer tools, but when I share the link to this page the image and description are not shown with a link. is it posible to implement it without SSR using react-helmet-async?

@chulinguy
Copy link

@Lenur29 I worked on this exact same issue.
IIRC, Facebook bot can sometimes "see" the updated metas from React-Helmet-Async, but not Twitter Bot.
I had to implement a conditional logic on the server for the bots.

@KaushikJnext
Copy link

KaushikJnext commented Apr 26, 2024

Hello @staylor I'm using react-helmet-async. could you assist me with managing dynamic meta tags for Google's web crawler effectively.

index.html
image

page.js
import { Helmet } from 'react-helmet-async';

<Helmet
onChangeClientState={newState => {
// Add description
const metaDescription = document.querySelector(
'meta[name="description"]'
);
if (metaDescription) {
metaDescription.setAttribute('content', description || '');
}
}}
>
<title>{title}</title>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants