We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34162
    • 1 Posts
    はじめまして。ちょっと前にMODxを導入しました。

    ところで出力されたページの<head>内を見ると、

    <meta http-equiv="keywords" content="キーワード" />
    <title>タイトル | ページタイトル</title>
    <meta http-equiv="Content-Type" content="text/html; 文字コードセット" />

    となっていて、この並びはあまり良くありません。

    http-equiv="keywords" や <title> には各言語でキーワードが設定されることがあり、
    http-equiv="Content-Type" の行が一番上にこなければまずいです。

    http-equiv="Content-Type" と <title> の位置はテンプレートの設定で変えられました。
    しかし、 http-equiv="keywords" は勝手に <head> 内の最上部に挿入されてしまいます。

    正しくは、

    <meta http-equiv="Content-Type" content="text/html; 文字コードセット" />
    <title>タイトル | ページタイトル</title>
    <meta http-equiv="keywords" content="キーワード" />

    とならなくてはいけませんが、
    「METAキーワード」機能を使っている場合に http-equiv="keywords" の挿入位置をこのように直すことはできますか?

    よろしくお願いします。
      • 8382
      • 253 Posts
      marnさん。こんにちは laugh
      いまどきのブラウザは、殆どHTTPヘッダで渡されるContent-Typeオプションでエンコードを判断しますので、実害はほぼ無いはずです。
      IEの場合ですとエンコードではなく、lang属性でフォントを選んでいるもあるので見た目が気になる場合はその辺もご注意を。

      ですが、気持ち悪いと言うのはとても理解できますので、ちょっと仕組みを調べてみます。
      少しややこしい所ではあるのですが。他の方もわかる方は是非情報を。 wink
        • 8382
        • 253 Posts
        marnさん。
        対処としては、Content-Typeをメタタグに登録するか、もしくはテンプレートに書くかにより方法が分かれます。
        1.メタタグに登録する場合。
        manager/includes/document.parser.class.inc.php line 568 function mergeDocumentMETATags 内
            if($this->documentObject['haskeywords']==1) {
              // insert keywords
              $keywords = implode(", ",$this->getKeywords());
              $metas = "\t<meta http-equiv=\"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";
              }
            }
        

            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";
              }
            }
            if($this->documentObject['haskeywords']==1) {
              // insert keywords
              $keywords = implode(", ",$this->getKeywords());
              $metas .= "\t<meta http-equiv=\"keywords\" content=\"$keywords\" />\n";
            }
        
        とする。

        2.テンプレートに書く場合
        同じくmanager/includes/document.parser.class.inc.php line 584 function mergeDocumentMETATags 内
            $template = preg_replace("/(<head>)/i", "\\1\n".$metas, $template);
        

            $template = preg_replace("/(</head>)/i", $metas."\\1\n", $template);
        
        とする。

        こんな感じではないかと。お試しください。
          • 34162
          • 1 Posts
          eastbindさん

          修正部分のコードまでご返信いただきありがとうございます。
          さっそく試してみたいと思います。

          MODxはまだまだ触り始めたばかりですが多くの可能性を秘めていますね。
          今後の進化も非常に楽しみです。

          どうもありがとうございました。
            • 8382
            • 253 Posts
            marnさん。ごめんなさい lipsrsealed
                $template = preg_replace("/(</head>)/i", $metas."\\1\n", $template);
            
            とする。

            のところですが、
                $template = preg_replace("/(<\/head>)/i", $metas."\\1\n", $template);
            
            じゃないと駄目かもしれませんてか、駄目だと思います。
            試してしまってたら、本当に申し訳ないです。 :’(
              • 34162
              • 1 Posts
              eastbindさん

              訂正、ありがとうございます。
              これで無事、気になる点が直りました smiley