We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17665
    • 54 Posts
    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... undecided

    $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.
      • 17282
      • 283 Posts
      this is exactly what i need .. i want the same keywords throuout the site smiley

      Kudos
        Everytime you use Flash ... a puppy dies .....
        R.G Taylor
        • 2762
        • 1,198 Posts
        Cool! i never thought about this solution! should be a great! wink

        I have proposed in the wishlist forum : http://modxcms.com/forums/index.php/topic,2383.0.html that should be another good keyword tool.
          Free MODx Graphic resources and Templates www.tattoocms.it
          -----------------------------------------------------

          MODx IT  www.modx.it
          -----------------------------------------------------

          bubuna.com - Web & Multimedia Design
        • 	$tagstyle = $col['http_equiv'] ? 'http_equiv':'name';


          That will fail validation, it has to be ’http-equiv’ instead:

          	$tagstyle = $col['http_equiv'] ? 'http-equiv':'name';
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org