Front end developer specialising in JavaScript and React. Experienced in all aspects of modern front end development. Passionate about making accessible, secure and performant software.
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:
constmaybeDescriptionMetaTag=document.querySelector('meta[name=description');// select the tagif(maybeDescriptionMetaTag){// if the meta tag already existsmaybeDescriptionMetaTag.setAttribute('content','My new description');// Overwrite the content attribute}else{constdescriptionMetaTag=document.createElement('meta');// create a meta tagdescriptionMetaTag.setAttribute('name','description');// add the name attribute and valuedescriptionMetaTag.setAttribute('content','The description of the page goes here');// add the content attribute and valuedocument.head.append(descriptionMetaTag);// insert the tag into the <head> element}
Hope that helps!
EDIT: A lot. Submitted by accident with CTRL+ENTER
Top comments (3)
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:
Hope that helps!
EDIT: A lot. Submitted by accident with CTRL+ENTER
thanks a lot !!!
okay