概要
elementor/template_library/sources/local/register_taxonomy_cptsアクションは、WordPressのElementorプラグインにおいてカスタムポストタイプやカスタムタクソノミーを登録する際に使用されるフックです。このアクションは、テンプレートライブラリにおけるローカルなデータソースの登録を可能にし、特に以下の機能を実装する際によく使われます。
- オリジナルなテンプレートの管理
- 特定の投稿タイプに対するカスタムタクソノミーの追加
- 動的コンテンツの表示
- テンプレート選択の拡張
- WordPressのダッシュボードでの管理機能の向上
- Elementorでのデザインの自由度向上
このアクションはElementorのバージョンが2.0以上、WordPressのバージョンが4.0以上で利用可能です。
構文
do_action( 'elementor/template_library/sources/local/register_taxonomy_cpts' );
パラメータ
このアクションにはパラメータはありません。
戻り値
戻り値はありません。
サンプルコード
サンプルコード1: カスタムポストタイプの登録
add_action( 'elementor/template_library/sources/local/register_taxonomy_cpts', function() {
register_post_type( 'portfolio', [
'labels' => [
'name' => 'ポートフォリオ',
'singular_name' => 'ポートフォリオ'
],
'public' => true,
'has_archive' => true,
]);
});
このコードは「ポートフォリオ」というカスタムポストタイプを登録します。
URL: https://developer.wordpress.org/reference/functions/register_post_type/
サンプルコード2: カスタムタクソノミーの登録
add_action( 'elementor/template_library/sources/local/register_taxonomy_cpts', function() {
register_taxonomy( 'genre', 'portfolio', [
'label' => 'ジャンル',
'hierarchical' => true,
]);
});
このコードは「ポートフォリオ」ポストタイプに対して「ジャンル」というカスタムタクソノミーを登録します。
URL: https://developer.wordpress.org/reference/functions/register_taxonomy/
サンプルコード3: 投稿タイプサポートの追加
add_action( 'elementor/template_library/sources/local/register_taxonomy_cpts', function() {
add_post_type_support( 'portfolio', 'thumbnail' );
});
このコードは「ポートフォリオ」ポストタイプに対し、サムネイルのサポートを追加します。
URL: https://developer.wordpress.org/reference/functions/add_post_type_support/
サンプルコード4: カスタムメタボックスの追加
add_action( 'elementor/template_library/sources/local/register_taxonomy_cpts', function() {
add_meta_box( 'portfolio_details', 'ポートフォリオ詳細', 'portfolio_details_callback', 'portfolio' );
});
このコードは「ポートフォリオ」ポストタイプに対してカスタムメタボックスを追加します。
URL: https://developer.wordpress.org/reference/functions/add_meta_box/
サンプルコード5: 投稿タイプの管理メニューを追加
add_action( 'elementor/template_library/sources/local/register_taxonomy_cpts', function() {
register_post_type( 'portfolio', [
'menu_position' => 5,
'has_archive' => true,
]);
});
このコードは「ポートフォリオ」ポストタイプを特定の管理メニューの位置に追加します。
URL: https://developer.wordpress.org/reference/functions/register_post_type/
この関数のアクションでの使用可能性
| アクション名 | 使用例 |
|---|---|
| mu_plugin_loaded | 〇 |
| registered_post_type | 〇 |
| plugins_loaded | 〇 |
| wp_roles_init | |
| setup_theme | |
| after_setup_theme | |
| set_current_user | |
| init | 〇 |
| register_sidebar | |
| wp_loaded | |
| send_headers | |
| parse_query | |
| pre_get_posts | |
| wp | 〇 |
| template_redirect | |
| get_header | |
| wp_head |
この表は、elementor/template_library/sources/local/register_taxonomy_cptsアクションがどのアクションで使用されるかを示しています。