WP Manifestindependent plugin directory
manifest / content / baizy-term-color

Baizy Term Color

タクソノミーのタームに背景色設定機能(カラーピッカー)を追加します。ターム単位で背景色を term meta として保存し、テンプレートから取得できます。

★ 0stars

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/yukiuota/baizy-term-color/archive/refs/heads/main.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

タクソノミーのタームに背景色設定機能(カラーピッカー)を追加する WordPress プラグインです。 baizy テーマから独立させたもので、テーマに依存せず単体で動作します。 背景色は term meta(term_bg_color)として保存されるため、テーマを切り替えてもデータは保持されます。

必要環境

  • WordPress 6.0+
  • PHP 8.0+

インストール

  1. このディレクトリを wp-content/plugins/baizy-term-color/ に配置
  2. 管理画面 →「プラグイン」→「Baizy Term Color」を有効化

使い方

対象タクソノミーの設定

デフォルトでは sample-category タクソノミーで有効です。 対象を変更するには baizy_term_color_taxonomies フィルターを使います(テーマの functions.php 等)。

// 対象タクソノミーを変更
add_filter( 'baizy_term_color_taxonomies', fn() => array( 'news-category', 'news-tag' ) );

// 個別に追加する場合(従来どおり関数呼び出しも可能)
add_term_background_color_field( 'sample-category' );
add_term_background_color_field( array( 'news-category', 'news-tag' ) );

対象タクソノミーの新規追加・編集画面にカラーピッカー付きの「背景色」フィールドが表示されます。

テンプレートでの利用

$color = get_term_background_color( $term_id ); // '#ffffff'(未設定は空文字)
$style = get_term_background_style( $term_id ); // 'style="background-color: #ffffff;"'

プラグインが無効な環境でもテンプレートが壊れないよう、function_exists() ガードの利用を推奨します。

$bg_color = function_exists( 'get_term_background_color' ) ? get_term_background_color( $term['term_id'] ) : '';

構成

baizy-term-color/
├── baizy-term-color.php      プラグイン本体(フィールド追加・保存・取得関数)
└── assets/
    └── term_color_picker.js  カラーピッカー初期化スクリプト