There’s a few posts here and there about Keywords and META Tags and I’ve seen [[GetKeywords]] show up here and there but I don’t see it in the repository anywhere... It’s entirely possible that I’m missing something completely obvious about adding keywords and meta tags globally and there is a better way to do this... but in case not, I just hacked up a snippet (blatantly stealing from the API mergeDocumentMETATags function). Hopefully this is useful to someone... unless, or course, this is the wrong way to do this...
$id = isset($id) ? $id : $modx->documentIdentifier;
$keywords = $modx->getKeywords($id);
$tags = $modx->getMETATags($id);
$metas = "";
// insert meta tags
foreach ($tags as $n=>$col) {
$tag = strtolower($col['tag']);
$tagvalue = $col['tagvalue'];
$tagstyle = $col['http_equiv'] ? 'http-equiv':'name';
$metas.= "\t<meta $tagstyle=\"$tag\" content=\"$tagvalue\" />\n";
}
// insert keywords
$keywords = implode(", ",$keywords);
$metas .= "\t<meta http-equiv=\"keywords\" content=\"$keywords\" />\n";
return $metas;
The idea behind it being you can set some keywords for a document (for example, your root document with id=1), then modify your template (or HeaderChunk) so that all your documents get the same keywords as your root document: [[GetKeywordsAndMETATags? &id=1]].
Or, if you have a group of documents that all relate to eachother and you want them all to have the same keywords, you can set the parent up and then just use this snippet on all the child docs.
I don’t know much about search engine stuff and all that, but I was asked to add keywords and meta tags to our website and this is the only way I could think of to do it for the whole site.