Movable Type のテンプレートで作る meta タグの keywords と description

Movable Type で meta タグの keywords と description を挿入するテンプレートを考えてみました。SEO 対策としてどれだけ効果があるかは疑問ですが、ないよりはマシということで。 「ないよりはマシ」とは言っても、正確にはヘタな keywords と description を入れるくらいだったな無い方がマシのようですので、以下の点だけ気を付けます。 keywo...

Movable Type で meta タグの keywords と description を挿入するテンプレートを考えてみました。SEO 対策としてどれだけ効果があるかは疑問ですが、ないよりはマシということで。

「ないよりはマシ」とは言っても、正確にはヘタな keywords と description を入れるくらいだったな無い方がマシのようですので、以下の点だけ気を付けます。

  • keywords : 5 、6 個にし、他のページと極力同じにならないようにする。
  • description : おおよそ 100 字以内にし、他のページと極力同じにならないようにする。

これだけ意識して、以下のような Movable Type のテンプレートにしてみました。

<mt:If name="main_index">
 <meta name="keywords" content="XHTML,CSS,JavaScript,Movable Type,WordPress,Webデザイン,CMS" />
 <meta name="description" content="<$mt:BlogDescription$>" />
<mt:ElseIf name="archive_index">
 <meta name="keywords" content="<mt:Entries lastn="2"><mt:If name="__first__"><mt:EntryCategories glue=","><$mt:CategoryLabel regex_replace="/[0-9]+_/",""$></mt:EntryCategories><mt:ElseIf name="__last__"><mt:EntryIfTagged>,<mt:EntryTags glue=","><$mt:TagName$></mt:EntryTags></mt:EntryIfTagged></mt:If></mt:Entries>" />
 <meta name="description" content="<mt:Entries lastn="5"><$mt:EntryTitle encode_html="1"$>,</mt:Entries>" />
<mt:ElseIf name="entry_template">
 <meta name="keywords" content="<$mt:EntryKeywords$>" />
 <meta name="description" content="<$mt:EntryExcerpt$>" />
<mt:ElseIf name="page_template">
 <meta name="keywords" content="<$mt:PageKeywords$>" />
 <meta name="description" content="<$mt:PageExcerpt$>" />
<mt:ElseIf name="archive_listing">
 <meta name="keywords" content="<mt:Entries lastn="2"><mt:If name="__first__"><mt:EntryCategories glue=","><$mt:CategoryLabel regex_replace="/[0-9]+_/",""$></mt:EntryCategories><mt:ElseIf name="__last__"><mt:EntryIfTagged>,<mt:EntryTags glue=","><$mt:TagName$></mt:EntryTags></mt:EntryIfTagged></mt:If></mt:Entries>" />
 <meta name="description" content="<mt:Entries lastn="5"><$mt:EntryTitle encode_html="1"$>,</mt:Entries>" />
</mt:If>

メインページ

  • keywords : テンプレートに直接記述
  • description : ブログの説明を表示
<mt:If name="main_index">
 <meta name="keywords" content="XHTML,CSS,JavaScript,Movable Type,WordPress,Webデザイン,CMS" />
 <meta name="description" content="<$mt:BlogDescription$>" />

メインページは単純です。

アーカイブインデックス

  • keywords : アーカイブインデックスにリストアップされるブログ記事の、1 件目のブログ記事が属するカテゴリ、2 件目のブログ記事に付いているタグを表示
  • description : アーカイブインデックスにリストアップされる最新 5 件のブログ記事のタイトルを表示
<mt:ElseIf name="archive_index">
 <meta name="keywords" content="<mt:Entries lastn="2"><mt:If name="__first__"><mt:EntryCategories glue=","><$mt:CategoryLabel regex_replace="/[0-9]+_/",""$></mt:EntryCategories><mt:ElseIf name="__last__"><mt:EntryIfTagged>,<mt:EntryTags glue=","><$mt:TagName$></mt:EntryTags></mt:EntryIfTagged></mt:If></mt:Entries>" />
 <meta name="description" content="<mt:Entries lastn="5"><$mt:EntryTitle encode_html="1"$>,</mt:Entries>" />

keywords をこのようにするのは、最新 2 件のカテゴリにしてしまうと、重複する可能性が高いためです。ただし、カテゴリよりもタグの方が「キーワード」には馴染みにくい気もしますので、タグの名前の付け方によってはカテゴリだけにした方が良い可能性もありますね。

ブログ記事

  • keywords : ブログ記事の編集画面の「キーワード」欄を表示
  • description : ブログ記事の概要を表示
<mt:ElseIf name="entry_template">
 <meta name="keywords" content="<$mt:EntryKeywords$>" />
 <meta name="description" content="<$mt:EntryExcerpt$>" />

ブログ記事の概要は、ブログ記事の編集画面で「概要」に入力しているときはその内容が、入力していないときはブログ記事本文の最初の x 文字が表示されます。

最初の x 文字は、「設定」>「ブログ記事設定」>「概要の文字数」で設定します。

ウェブページ

  • keywords : ウェブページの編集画面の「キーワード」欄を表示
  • description : ウェブページの概要を表示
<mt:ElseIf name="page_template">
 <meta name="keywords" content="<$mt:PageKeywords$>" />
 <meta name="description" content="<$mt:PageExcerpt$>" />

ブログ記事と同様です。

ブログ記事リスト

  • keywords : リストアップされるブログ記事の、1 件目のブログ記事が属するカテゴリ、2 件目のブログ記事に付いているタグを表示
  • description : リストアップされる最新 5 件のブログ記事のタイトルを表示
<mt:ElseIf name="archive_listing">
 <meta name="keywords" content="<mt:Entries lastn="2"><mt:If name="__first__"><mt:EntryCategories glue=","><$mt:CategoryLabel regex_replace="/[0-9]+_/",""$></mt:EntryCategories><mt:ElseIf name="__last__"><mt:EntryIfTagged>,<mt:EntryTags glue=","><$mt:TagName$></mt:EntryTags></mt:EntryIfTagged></mt:If></mt:Entries>" />
 <meta name="description" content="<mt:Entries lastn="5"><$mt:EntryTitle encode_html="1"$>,</mt:Entries>" />

アーカイブインデックスと同様です。

以上、結果としてあまり面白みのないエントリーになってしましました。でも途中はいろいろと試行錯誤しているのです。これがテンプレートをいじる面白みの一つでもあったりしますw。

Published 2008-08-26
Updated 2019-06-25