ページ内目次

body_class()に独自のクラスを追加

多くのテンプレートで既に埋め込まれていますが、bodyタグにbody_class()を埋め込んでやると、自動的にいくつかのcssクラスを吐き出してくれます。

<body <?php body_class(); ?>>

どのページのときに何が吐き出されるかの詳細は、こちらのページに書いてあります。

では、それプラス、独自のタグも追加したいというときにはどうすれば?

<body <?php body_class('class-name01 class-name02 class-name03'); ?>>

という具合に追加すれば良いですね。

 

ちなみに私の場合は、各ページにページのスラッグも吐き出させたい派なので、「bodyタグのクラスに固定ページのスラッグを追加」に書いた方法でゴニョゴニョしてます。

 

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny

↑上へまいりま〜す