简体   繁体   中英

How can override a meta tag?

I have a website hosted in an absurd place. Earlier today, they added this to the "Head" section of my pages.

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

Unfortunately, I cannot change the code directly, but I do have access to Robots.txt (which they also screwed, but I already fixed it), JavaScript and Html. Is there any way I can remove that one tag from my website? I tried this one solution, but it doesn't seem to be working:

document.querySelector('meta[name="robots"]').setAttribute("content", "all");

Any other ways I can do this, besides the obvious "it's about time you move to a different host lol"? Maybe there is, ultimately, something I can add to Robots.txt to override this?

Have you tried removing the meta tag from the dom and adding a new one?

Like this:

document.querySelector("[name='robots']").remove();

let metatag = document.createElement('meta');
metatag.setAttribute('name', 'robots');
metatag.content = 'all';
document.getElementsByTagName('head')[0].appendChild(metatag);

You can select the element using this code

document.querySelector("[name='geo.region']")

now once you have access to it, you can override it

if overriding doesn't work, use a hammer:)

remove the existing meta node

document.querySelector('meta[name="robots"]').remove();

create a new one with desired attribute;

const newMeta = document.createElement("meta");
newMeta.setAttribute("name", "robots");
newMeta.setAttribute("content", "all");
document.head.appendChild(newMeta);

After a few hours of considering all kinds of possible solutions, I eventually noticed that a much simpler piece of code could work. Instead of all this, and since I could not remove code but could add to it, I simply added this:

<meta name="robots" content="all" />
<meta name="googlebot" content="all" />

This made it worked... the bots may be feeling confused, "hey, should I index it or not, afterall?,", but it works. and that's what matters to me.

Thank you very much for your help, everyone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM