We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32086
    • 13 Posts
    Hi all,

    for seo purporse...I need to insert TITLE tag for first in the head section.

    On my template is the first, but because I’ve create others meta tags (keyword, description etc) for some strange reason when I see source page of my modx website I see for firs tags that I’ve created and next the TITLE tag.

    I wish to put title tag for first for seo reasons. Any suggest ?

    thanks
      • 25663 MODX Staff
      • 12,272 Posts
      MODx does not change the way your templates output. Put them anywhere you’d like.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 22303 MODX Staff
        • 10,725 Posts
        Actually, if you are using the automatic keywords feature (or any other meta tags in manager interface), it will in fact place those immediately after the opening head tag. The only way around this now is either hacking the core code to insert these after the title tag as you want, or to choose another approach to assigning keywords or other metatags (i.e. put them directly in a TV you define and place that TV’s tag after the title tag in your template,
        <title>blah</title>[*mymetatv*]
        ).
          • 25663 MODX Staff
          • 12,272 Posts
          Good point Jason. Thanks!
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 32086
            • 13 Posts
            Thanks all for reply,

            Jason.....yes my problem Is that , I use "meta tags in maneger".
            Ok I’ll try by TV.

            If I go to hacking core code, is one file or it’s more complex ?

            thanks again
              • 22303 MODX Staff
              • 10,725 Posts
              The function is called mergeDocumentMETATags in manager/includes/document.parser.class.inc.php, at around line 609 in the 0.9.5 release. The next to last line of the function (625) does a preg_replace to place the meta tags right after the opening head tag:
                  function mergeDocumentMETATags($template) {
                      if ($this->documentObject['haskeywords'] == 1) {
                          // insert keywords
                          $keywords= implode(", ", $this->getKeywords());
                          $metas= "\t<meta name=\"keywords\" content=\"$keywords\" />\n";
                      }
                      if ($this->documentObject['hasmetatags'] == 1) {
                          // insert meta tags
                          $tags= $this->getMETATags();
                          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";
                          }
                      }
                      $template= preg_replace("/(<head>)/i", "\\1\n" . $metas, $template);
                      return $template;
                  }
              

              You could modify that to look for the closing title tag instead; just make sure all of your templates have a title tag...