WordPressで自動でmetaタグのkeywordsとdescriptionを表示
metaタグのkeywordsとdescriptionにて、基本的にはAll in One SEOとかで手動で設定していくべきなんだろうけど、記事数勝負のコンテンツとか自動生成系のコンテンツだとどうにもならないので、自動で表示する方法をメモ。
PC側テーマのヘッダー部分に下記ソースを記述。
<!--description&keywords--> <meta name="description" content="<?php if(is_home()){ ?>トップページに表示したいdescriptionを書く<?php } elseif (is_single()){ $content_summary = strip_tags($post->post_content); $content_summary = ereg_replace("(\r\n|\r|\n)", "", $content_summary); $content_summary = mb_substr($content_summary, 0, 60). "..."; $content_summary=strip_tags($content_summary); echo $content_summary; } else { ?><?php bloginfo('description'); ?><?php } ?>"> <meta name="keywords" content="<?php if(is_home()) { ?>トップページに設定したいキーワード,キーワード①,キーワード②<?php } elseif (is_single()){ ?><?php $posttags = get_the_tags();if ($posttags) {foreach($posttags as $tag) {echo $tag->name . ','; }} ?><?php the_title(); ?><?php } else {?>デフォルトのキーワード①,デフォルトのキーワード②<?php } ?>"> <!--description&keywords-->
あとは必要に応じて、
$content_summary = ereg_replace("\"", "", $content_summary);
とかで修正していく。
参考サイト
関連記事
-
-
WordPressのxmlrpc.phpへの攻撃
サーバーの死活監視をしているシステムから、1つのサイトが落ちているとアラートがき ...
-
-
SEOの勉強会があった
社内でSEOに関する勉強会があった。 広告の部署が、他の色々な部署に説明する為、 ...
-
-
contact form7で500エラー
WordPressプラグインのcontact form7で送信ボタンを押し、ロー ...
-
-
WordPressでSNSボタンが表示されない
WordPressでWordPress WP Social Bookmarkin ...
-
-
Polylangで言語毎の分岐処理
WordPressで多言語サイトを作成するにあたりPolylangというプラグイ ...
-
-
WordPressで逆アクセスランキングの設置
WordPressに逆アクセスランキングを設置したかった。 ただ、広告が出ないタ ...
-
-
PHPでaタグにnofollowを付ける
タイトルそのまま、リンクがあった場合に nofollowつけてくれ、というもの。 ...
-
-
WordPressにお気に入り登録機能とお気に入り一覧ページを作成する方法
WordPressにお気に入り登録機能をつけたかった。 会員制のサイトじゃなかっ ...
-
-
WordPressで閲覧者にテーマを変更させるプラグイン
「新規サイトを○○みたいなイメージでWordPressのテーマを見繕って欲しい」 ...
-
-
WordPressでスケジュール実行される日時を調べる方法
WordPressであるシステムを実装し、その際に毎日1回スケジュール実行(WP ...