Reputation:
Is there a way to remove title tag using javascript?
I tried to do this
var parent = document.head;
var child = document.title;
parent.removeChild(child);
but it failed because title tag is not a node (console said). I need to force a Wordpress plugin to overwrite the default title tag with a custom one.
Any ideas?
Upvotes: 1
Views: 4653
Reputation: 3839
To set document title via JS, use:
document.title = "your title here"
Note that the title you set via JS will not be visible to Google and other search engines.
Upvotes: 0
Reputation: 943214
The title
property just contains a string representation of the title. It doesn't represent the element itself.
You can use any of the usual methods to get the element itself.
document.querySelector("title");
document.getElementsByTagName("title")[0]
// etc
Upvotes: 1