Search code examples
htmlweb-crawlermeta-tags

How to override an existing meta tag in html?


I have an html document with this meta tag :

<meta name="robots" content="noindex, nofollow"> 

I want to keep this tag in the head but override it with this new declaration :

<meta name="robots" content="index, follow">

Should i put the overriding tag before or after the first one ?


Solution

  • If we consider only the robots meta tag:

    The best possible way will be to include ONLY the correct meta tag in the page output.


    There is no HTML convention to override meta tags, so the effect of having multiple conflicting meta tags will be interpreted differently by the the different services (browsers, search engines, etc.) using them.

    In your case there is no guarantee how different search engines will follow your robots instructions. Some of them may use the first occurrence, others may used the last occurrence and Google may use the more restrictive instruction.

    The last one was mentioned here Official Google Blog Post, but it's from 2007 and things may changed.


    Although there is a way to change dynamically the content of meta tags with Jquery by using something like:

    $("meta[name='robots']").attr('content', 'index, follow'); 
    

    There is again no guarantee that this will take the desired effect. Google executes JavaScript when crawling your page (I'm not sure it will respect this), but other search engines may not.

    Additional information about Google executing JavaScript when crawling pages: