EC-CUBE ページタイトルの変更方法
EC-CUBEでちょっと便利の悪い部分はページタイトル。
管理画面で、編集できるようになればかなり便利なんですけどね。
でも、出来ないものはしかたないので今回はEC-CUBEのページタイトル(<title>~</title>)、キーワード(keywords)、ディスクリプション(description)の変更方法を僕的に一番手っ取り早い方法でご説明します。
間違っちゃうと、色々面倒なんで、最初の状態をバックアップしてからカスタマイズをはじめた方がいいと思います。
今回のEC-CUBEバージョンは2.4.3です。
data/Smarty/templates/site_frame.tplの変更
data/Smarty/templates/site_frame.tpl を変更します。間違えるといけないんで慎重にやってください!
site_frame.tpl カスタマイズ前
data/Smarty/templates/site_frame.tplのカスタマイズ前に記載されている下記のタグを削除します。
<title><!--{$arrSiteInfo.shop_name|escape}-->/<!--{$tpl_title|escape}--></title> <meta name="description" content="<!--{$arrPageLayout.description|escape}-->" /> <meta name="keywords" content="<!--{$arrPageLayout.keyword|escape}-->" />
site_frame.tpl カスタマイズ後
カスタマイズ前のタグを削除したら、今度は下記のコードを記入します。
記入後、保存してdata/Smarty/templates/site_frame.tplに上書き保存。
<!--{assign var=top value="`$smarty.const.URL_DIR`index.php"}--> <!--{assign var=list value="`$smarty.const.URL_DIR`products/list.php"}--> <!--{assign var=detail value="`$smarty.const.URL_DIR`products/detail.php"}--> <!--トップページ用--> <!--{if $smarty.server.PHP_SELF==$top}--> <title><!--{$arrSiteInfo.shop_name}--></title> <meta name="description" content="<!--{$arrPageLayout.description|escape}-->" /> <meta name="keywords" content="<!--{$arrPageLayout.keyword|escape}-->" /> <!--商品一覧用--> <!--{elseif $smarty.server.PHP_SELF==$list}--> <!--{if $tpl_subtitle != "全商品"}--> <title><!--{$tpl_subtitle}--> | <!--{$arrSiteInfo.shop_name}--></title> <!--{else}--> <title><!--{$arrPageLayout.description|escape}--> | <!--{$arrSiteInfo.shop_name}--></title> <!--{/if}--> <meta name="description" content="<!--{$arrPageLayout.description|escape}-->" /> <meta name="keywords" content="<!--{$arrPageLayout.keyword|escape}-->" /> <!--商品詳細用--> <!--{elseif $smarty.server.PHP_SELF==$detail}--> <title><!--{$tpl_title|escape}--> | <!--{$arrSiteInfo.shop_name}--></title> <meta name="description" content="<!--{$arrProduct.main_list_comment|escape|regex_replace:"/[\r\t\n]/":""}-->" /> <meta name="keywords" content="<!--{if $arrProduct.comment3}--><!--{$arrProduct.comment3|escape|regex_replace:"/[\r\t\n]/":""|regex_replace:"/、/":","}--><!--{/if}-->" /> <!--その他--> <!--{else}--> <title><!--{$tpl_title|escape}--> | <!--{$arrSiteInfo.shop_name}--></title> <meta name="description" content="<!--{$arrPageLayout.description|escape}-->" /> <meta name="keywords" content="<!--{$arrPageLayout.keyword|escape}-->" /> <!--{/if}-->
ただこれだけでは商品詳細のページタイトルに商品詳細が表示されたままになります。 これがある意味一番うっとうしいです 苦笑 何のために最初から入ってるかわかりません。
商品詳細のページタイトルから商品詳細を消す
/data/class/pages/product/LC_Page_Products_Detail.phpの編集が必要になってきます。
/data/class/pages/product/LC_Page_Products_Detail.phpの編集
253行目の変更
$this->tpl_title = "商品詳細". $this->arrProduct["name"];
商品詳細という文字を消します。
$this->tpl_title = "". $this->arrProduct["name"];
458行目の変更
$this->tpl_title = "商品詳細 ". $this->arrProduct["name"];
同じく、商品詳細という文字を消します。
$this->tpl_title = "". $this->arrProduct["name"];要は、253行目と458行目の商品詳細を消せばいいって事です。
以上の作業で完了です、次は各ページのページタイトル設定に移ります。
管理画面での編集
基本情報設定>SEO管理でトップページ(index.php)、商品一覧(products/list.php)、商品詳細(products/detail.php)、MYページ(mypage/index.php)のページタイトル、キーワード、ディスクリプションの設定が可能です。
ただし、ここでは商品詳細の記入は必要ありません。商品詳細に関しては商品管理ページ> 商品登録に表示される検索ワード、一覧 - メインコメントに記入してもらうことでページに反映されます。
SEO的にもEC-CUBE初期設定より効果があるし、あまり難しく考えないならこの方法で十分だと思います。何か気になる事、気付いた事があれば追記、または修正します。