てっきんの具。

「てっきん」と呼ばれて40年のおっさんが書くブログ

[2019年版] BuddyPressで子テーマを作る方法

2011年に書いた記事「BuddyPressで子テーマを作る方法」が久しぶりに Twitter でシェアされたのを機に、あらためて記事を書き起こすことにしました。

というのも BuddyPress のコードを久しぶりに見てみたところ、BuddyPress 同梱のテンプレートを適用する方法がガラっと変わっていたからなんです。

今どきの BuddyPress 子テーマの作り方

  1. Codex 日本語版「子テーマ」の項に示された手順に沿って、子テーマのディレクトリ, style.css, functions.php を作成。ここでは、テーマ名を「FooBar」、ディレクトリ名を foobar とすることにします。
  2. テーマ「FooBar」を有効化。これで、子テーマに BuddyPress 内蔵のテンプレートが適用されます。本記事執筆時点で、「BuddyPress設定」で選択できる内蔵テンプレートセットは下記の2種類。
    • BuddyPress レガシー
    • BuddyPress Nouveau
  3. BuddyPress のテンプレートセットは
    /wp-content/plugins/buddypress/bp-templates/ 内にテンプレートセットごとのディレクトリに分けられています。カスタマイズしたいテンプレートファイルを選び、子テーマディレクトリ内にコピーします。

テンプレートファイルをコピーする際は bp-templates/{template-name}/ 内の階層構造をそのまま保持します。たとえば、BuddyPress レガシー(bp-legacy)の「アクティビティ」テンプレートをカスタマイズしたい場合、下記のような配置になります。

  • コピー元
    • /wp-content/plugins/buddypress/bp-templates/bp-legacy/activity/index.php
  • コピー先
    • /wp-content/themes/foobar/buddypress/activity/index.php

下記の情報源を参考にしました

stopped offering bp-default on installations that are not already using it. That means that if your site is not already running bp-default (or a child theme of bp-default), BuddyPress 1.9 will not register its bp-themes directory, and bp-default will not show up on Dashboard > Appearance. This’ll ensure that new installations don’t get locked into using the now-sunsetted bp-default theme.

The future of the bp-default theme | BuddyPress Dev Updates

《拙訳》
(BuddyPress 開発貢献者のワークフローを簡素化するため)、新規 BuddyPress インストール時にはデフォルトテーマ「bp-default」を登録しないようにしました。つまり、「bp-default」(または、その子テーマ)を実行していない場合、 ダッシュボード > 外観 > テーマ の設定画面には bp-default が表示されないということになります。(BuddyPress の)新規インストールでは、これまでの bp-default に縛られないテーマ開発が可能となります。

Overloading Template Compatibility theme files

Template compatibility also runs a check to see if two directories or folders exist in a theme:

‘buddypress’
‘community’

If either of these two folders exist in your theme and they contain BP template files then those files will be used in preference to the bp plugins versions.

Therefore, you can modify any bp theme compatibility template by copying it over from:

/bp-templates/bp-legacy/buddypress/

To:

/my-theme/community/ or /my-theme/buddypress/
N.B. Inside the subfolder ‘community’ you must preserve the path structure/folders that exist in the BP original /buddypress/ folder so /activity/ must be created to hold index.php or any of the other activity templates.

Theme Compatibility & Template Files

《拙訳》
テンプレートファイルのオーバーロード(上書き)
(BuddyPress は)テーマ内に下記のディレクトリが存在するかをチェックします。

* buddypress
* community

いずれかのディレクトリがテーマ内にあり、その中に BuddyPressのテンプレートファイルが含まれているときは、BuddyPress に同梱されるテンプレートよりも優先して使用されます。

BuddyPress 同梱のテンプレートは下記の場所からコピーして変更できます。

* コピー元 /bp-templates/bp-legacy/buddypress/
* コピー先 /my-theme/community/ または /my-theme/buddypress/

(注意)
サブディレクトリ community (または buddypress)内は、BuddyPress プラグイン内の階層構造を保持する必要があります。

カテゴリー:

タグ:

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください