LoginSignup
1
1

More than 5 years have passed since last update.

ページの slug を body のクラスに足す

Posted at

デフォルトでは page-id-9 のように ID が追加されますが、スタイルシートに書いたときにわかりにくいですよね。

わかりやすいように slug を足すには、テーマの functions.php に以下を追記します。

functions.php
function add_slug_body_class($classes) {
  global $post;
  if (isset($post)) {
    $classes[] = $post->post_type . '-' . $post->post_name;
  }
  return $classes;
}
add_filter('body_class', 'add_slug_body_class');

How to Add Page Slug in Body Class of your WordPress Themes より。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1