DEV Community

Dhiren Madhukar
Dhiren Madhukar

Posted on

does anyone know how to add seo tags n dynamic site in which database is taken from firebase ??

Top comments (3)

Collapse
 
sargalias profile image
Spyros Argalias • Edited

It depends. By using Firebase I'm assuming it's a front end app you're talking about?

In that case, then you need to use JavaScript to change the <title> tag and other SEO meta tags.

For the title you can do something like document.title = 'My New Title'. That will set the title of the page. So, any time you want to change the title, do that.

For the meta tags you need to select them first. For every meta tag, if it already exists on the page, you can overwrite the content attribute. If it doesn't already exist, then you need to create the entire meta tag and add it on the HTML head.

Here's some example code for changing / adding the description meta tag:

const maybeDescriptionMetaTag = document.querySelector('meta[name=description'); // select the tag
if (maybeDescriptionMetaTag) { // if the meta tag already exists
  maybeDescriptionMetaTag.setAttribute('content', 'My new description'); // Overwrite the content attribute
} else {
  const descriptionMetaTag = document.createElement('meta'); // create a meta tag
  descriptionMetaTag.setAttribute('name', 'description'); // add the name attribute and value
  descriptionMetaTag.setAttribute('content', 'The description of the page goes here'); // add the content attribute and value
  document.head.append(descriptionMetaTag); // insert the tag into the <head> element
}
Enter fullscreen mode Exit fullscreen mode

Hope that helps!

EDIT: A lot. Submitted by accident with CTRL+ENTER

Collapse
 
dhirenmadhukar profile image
Dhiren Madhukar

thanks a lot !!!

Collapse
 
dhirenmadhukar profile image
Dhiren Madhukar

okay