기본 게시물 유형 (또는 그 문제에 대한 다른 게시물)의 이름을 바꾸려면 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 );