デフォルトの投稿タイプ(またはその他の投稿タイプ)の名前を変更するには、filterを使用しますpost_type_labels_{$post_type}
。デフォルトpost
ではになりますpost_type_labels_post
。以下のコードには、ラベルの完全なリスト(WP 4.7.1
)があります。すべてを変更する必要はありません。
add_filter( 'post_type_labels_post', 'news_rename_labels' );
/**
* Rename default post type to news
*
* @param object $labels
* @hooked post_type_labels_post
* @return object $labels
*/
function news_rename_labels( $labels )
{
# Labels
$labels->name = 'News';
$labels->singular_name = 'News';
$labels->add_new = 'Add News';
$labels->add_new_item = 'Add News';
$labels->edit_item = 'Edit News';
$labels->new_item = 'New News';
$labels->view_item = 'View News';
$labels->view_items = 'View News';
$labels->search_items = 'Search News';
$labels->not_found = 'No news found.';
$labels->not_found_in_trash = 'No news found in Trash.';
$labels->parent_item_colon = 'Parent news'; // Not for "post"
$labels->archives = 'News Archives';
$labels->attributes = 'News Attributes';
$labels->insert_into_item = 'Insert into news';
$labels->uploaded_to_this_item = 'Uploaded to this news';
$labels->featured_image = 'Featured Image';
$labels->set_featured_image = 'Set featured image';
$labels->remove_featured_image = 'Remove featured image';
$labels->use_featured_image = 'Use as featured image';
$labels->filter_items_list = 'Filter news list';
$labels->items_list_navigation = 'News list navigation';
$labels->items_list = 'News list';
# Menu
$labels->menu_name = 'News';
$labels->all_items = 'All News';
$labels->name_admin_bar = 'News';
return $labels;
}
国際化のサポートが必要な場合は、次の__( $text, $textdomain )
ように使用します。
$labels->name = __( 'News', 'textdomain' );
関数でフィルタを見つけました:get_post_type_labels()
ファイルからwp-includes/post.php
:
/**
* Filter the labels of a specific post type.
*
* The dynamic portion of the hook name, `$post_type`, refers to
* the post type slug.
*
* @since 3.5.0
*
* @see get_post_type_labels() for the full list of labels.
*
* @param object $labels Object with labels for the post type as member variables.
*/
$labels = apply_filters( "post_type_labels_{$post_type}", $labels );