5

On my website the title is initially set through the title tag in the html served by my server. It is then changed to its dynamic equivalent through JavaScript.

I want Google to show my website's title as the static one in the HTML, but for some reason, Google is listing the title set by JavaScript.

This issue has plagued me for a long time and I'm still without a solution.

1
  • 1
    Thanks, I was wondering if Google did this. For my use it is actually wanted.
    – Steffan
    Commented Jul 12, 2023 at 6:45

4 Answers 4

1

The only solution that will not hurt your SEO is to prevent your JavaScript from changing the page title for that particular page (perhaps with an if statement as Warren mentioned).

A good rule of thumb (and the rules for many search engines including Google) is to always show the search engine the exact same thing you show the user. If you don't want it indexed in the search engine that way, simply don't show it to the user that way.

1

It sounds like all you need is a simple JavaScript if-type statement added to your code to keep it from changing the title on whatever page.

1

pages are example.com/day/date. They are all linked to the same base page but are changed dynamically relative to date.

I would ask yourself whether you need to change the page <title> (using client-side JavaScript) to specifically match the "dynamic" content, or just keep the generic catch-all title? What benefit does it give your users by changing the page title? If a user was to bookmark your page, the "dynamic" title will be bookmarked. If this is based on the date and the page content always contains content relating to the current date, then the bookmarked page title is going to become stale.

If you do change the <title> then consider changing the URL as well (using JavaScript pushState) so the two match. Although your comment ("...pages are example.com/day/date") perhaps suggests this is already the case?

0

What you are doing is a form of cloaking. It is against Google's Webmaster guidelines to show users one text and the search engine a different text. You need to set your titles such that the same title is seen by both users and Googlebot. If you show Googlebot different content, Google is likely to penalize your entire site such that it doesn't show up in the search results.

The reason that Google is picking up the dynamic title is that Googlebot is now able to execute the JavaScript. The fix should be to use the same title for both users and bots.

1
  • Well basically my index page is example.com and the other pages are example.com/day/date. They are all linked to the same base page but are changed dynamically relative to date. When it's the regualar example.com url I want a normal title.
    – WillBDev
    Commented Dec 6, 2018 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.