カテゴリー、タグページに説明文とアドセンスを追加

このサイトはWordPressの「twenty nineteen」を使っていますがカテゴリーとタグの設定にある説明文はデフォルトでは表示されません。

これを表示させるようにしたら検索でわかりやすくなるかなと思い設定してみました。

ついでにカテゴリーとタグページにアドセンスも追加しました。

カテゴリー、タグページに説明文を表示する

説明文の追加

外観→テーマエディターの「archive.php」の「</header>」の上に以下を追加します。(category.phpとtab.phpはない)
category_descriptionだけですがタグも説明文が表示されました。

これは条件分岐で2ページ目移行は表示されないようになっています。

<?php if(!is_paged()):?>
<?php if(category_description()):?>
<?php echo category_description(); ?>
<?php endif;?>
<?php endif;?>

参照
WordPressのカテゴリー、タグページに説明文を表示する方法

説明文でhtmlタグを使えるように変更

説明文でhtmlタグを使えるようにするには「function.php」に以下のコードを追加


remove_filter('pre_term_description', 'wp_filter_kses');

Pタグの除去

説明文には pタグがつくのだがそれを取り除くには以下を「function.php」に追加


remove_filter('term_description','wpautop');

参照
カテゴリーページや投稿タグページに入力した説明文を反映させる方法

Adsenseの追加

ヘッダにアドセンスの追加

外観→テーマエディターの「archive.php」の「</header>」の上に以下を追加します。説明文の表示に続けて追加。

</br></br>
				<script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-5993653051176297" data-ad-slot="2181898291"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

各ポストの下にアドセンス

カテゴリー、タグページ、検索結果の各ポストの下にアドセンスが表示されるようになる。

外観→テーマエディターの「content-excerpt.php (template-parts/content/content-excerpt.php)」の「</footer>の前にアドセンスを追加。

<script async="" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-5993653051176297" data-ad-slot="2181898291"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		
		
	</footer>

タグのボックスのサイズを広くする

「twenty nineteen」のデフォルトだとタグなどのあるボックスが692pxと幅が狭くなっているのでこれを削除

※「twenty nineteen」幅自体は他の設定にてすでに広げてあります。

スタイルシート (style.css) の 4280行目の「max-width」をコメントアウト


@media only screen and (min-width: 768px) {
  .entry .entry-footer {
    /* max-width: calc(6 * (100vw / 12) - 28px); */
  }
}

こちらで見え方をご確認ください。

パフォーマンス (category) / お誕生日会 (tag)

関連記事

http://magician.tokyo/wordpress-5-2-update
http://magician.tokyo/resize-multiple-images-by-mac
http://magician.tokyo/twenty-nineteen-footer-copyright
http://magician.tokyo/privacy-policy-added
http://magician.tokyo/wordpress-tag-and-date-url
http://magician.tokyo/prices

投稿日

カテゴリー:

投稿者: