$wp_post_types
是一个可容纳post_type
对象,这些对象依次具有labels
属性
您可以更改$wp_post_types[$post_type]->labels
在父主题设置了CPT之后。
将更高的优先级添加到init
钩
在主题中添加以下代码functions.php
文件
有关更多信息,请查看the codex article on get_post_type_object
.
function change_post_object_label() {
global $wp_post_types;
$labels = &$wp_post_types[\'portfolio\']->labels;
$labels->name = \'Property\';
$labels->singular_name = \'Property\';
$labels->add_new = \'Add Property\';
$labels->add_new_item = \'Add Property\';
$labels->edit_item = \'Edit Property\';
$labels->new_item = \'Property\';
$labels->all_items = \'All Properties\';
$labels->view_item = \'View Property\';
$labels->search_items = \'Search Property\';
$labels->not_found = \'No Property found\';
$labels->not_found_in_trash = \'No Property found in Trash\';
}
add_action( \'init\', \'change_post_object_label\', 999 );
在中添加以下代码
functions.php
从侧栏替换主菜单标签
function change_post_menu_label() {
global $menu;
//print_r($menu); Print menus and find out the index of your custom post type menu from it.
$menu[27][0] = \'Bacons\'; // Replace the 27 with your custom post type menu index from displayed above $menu array
}
add_action( \'admin_menu\', \'change_post_menu_label\' );
在中添加以下代码
functions.php
用于将图像添加到管理侧栏CPT菜单
add_action(\'admin_head\', \'change_CPT_icon\');
function change_CPT_icon() {?>
<style>
#menu-posts-portfolio .wp-menu-image { background: url(\'<?php echo get_bloginfo(\'template_directory\').\'/includes/images/new-image.png\';?>\') no-repeat 5px 5px transparent !important; }
</style>
<?php
}