If I put a div in the head and display:none, than use JavaScript to display it, will this work?
Edit:
I have stuff loaded in AJAX. And as my AJAX changes the
You can change meta with, for example, jQuery calls, like this ones:
$('meta[name=keywords]').attr('content', new_keywords);
$('meta[name=description]').attr('content', new_description);
I think it does matter for now, since google said that they will index ajax content via #!hashes
and _escaped_fragment_
calls. And now they can verify it (even automatically, with headless browsers, see the 'Creating HTML Snapshots' link on the page mentioned above), so I think it is the way for hardcore SEO guys.
For anyone trying to change og:title meta tags (or any other). I managed to do it this way:
document.querySelector('meta[property="og:title"]').setAttribute("content", "Example with og title meta tag");
Attention that the 'meta[property="og:title"]' contains the word PROPERTY, and not NAME.
No, a div is a body element, not a head element
EDIT: Then the only thing SEs are going to get is the base HTML, not the ajax modified one.
meta-tags are part of the dom and can be accessed and -i guess- changed, but search-engines (the main consumers of meta-tags) won't see the change as the javascript won't be executed. so unless you're changing a meta-tag (refresh comes to mind) which has implications in the browser, this might be of little use?
You can use more simpler and lighter solution:
document.head.querySelector('meta[name="description"]').content = _desc
$(document).ready(function() {
$('meta[property="og:title"]').remove();
$('meta[property="og:description"]').remove();
$('meta[property="og:url"]').remove();
$("head").append('<meta property="og:title" content="blubb1">');
$("head").append('<meta property="og:description" content="blubb2">');
$("head").append('<meta property="og:url" content="blubb3">');
});