Skip to content

A script changes the canonical or removes a noindex

rendered-head-mismatchserious
On this page

Why it matters

  • Google reads a page twice: its HTML as the server sends it, then, often later, the page its scripts make. Its JavaScript SEO guide says not to use a script "to change the canonical URL to something else than the URL you specified", and that a canonical a script adds must be "the only rel="canonical" link tag on the page".
  • When the two disagree, which address Google keeps as the page's own is not what either says for sure.
  • On noindex, the same guide says: "When Google encounters the noindex tag, it may skip rendering and JavaScript execution", so removing it with a script "may not work as expected". A page meant to be indexed should not say noindex in its HTML.
  • A script may set the canonical where the HTML has none, set the title and the description, or add a noindex (to an error page, say): Google's guide allows all of these, and this check does not report them.

Example

Wrong
<script>
  document.querySelector('link[rel="canonical"]').href = '/ar/oud/'
</script>
Right
<link rel="canonical" href="/ar/oud/" />

How to fix

Write the canonical and the robots meta the page should have in its HTML, and let no script change them:

html
<link rel="canonical" href="/ar/oud/" />
  • If a theme or a plugin rewrites the canonical in the browser, turn that off, or have the server write the right address.
  • If a page starts as noindex until a script decides, decide on the server instead.

How we detect

  1. We read the canonical link and the robots and googlebot metas in the HTML's <head>, as the server sent it.
  2. We render the page in Chromium, the engine Google renders with, and read the same in the head the scripts left.
  3. We report a canonical the scripts changed to another address, more than one canonical after the scripts ran, and a noindex in the HTML that the scripts removed. A noindex the X-Robots-Tag header sends cannot be removed by a script, and is not judged here; page-noindex reports every noindex.