我用了最后一天的时间使用这些函数。php文件为我的客户端站点完全定制WordPress。我很惊讶我能完成这么多,也很惊讶它能让我的客户更轻松。
我已删除了未以管理员身份登录的用户的某些菜单项。我希望(从我所读到的内容来看,我知道这是可以做到的)找到一种方法来重命名一些菜单项(管理区域的左侧边栏)。例如,将帖子更改为文章。
如果有人能提供函数的代码。php文件或指向我的方向,我将不胜感激!
我用了最后一天的时间使用这些函数。php文件为我的客户端站点完全定制WordPress。我很惊讶我能完成这么多,也很惊讶它能让我的客户更轻松。
我已删除了未以管理员身份登录的用户的某些菜单项。我希望(从我所读到的内容来看,我知道这是可以做到的)找到一种方法来重命名一些菜单项(管理区域的左侧边栏)。例如,将帖子更改为文章。
如果有人能提供函数的代码。php文件或指向我的方向,我将不胜感激!
下面是更改标签的过程(在我的示例中,我将帖子更改为“联系人”)
function change_post_menu_label() {
global $menu;
global $submenu;
$menu[5][0] = \'Contacts\';
$submenu[\'edit.php\'][5][0] = \'Contacts\';
$submenu[\'edit.php\'][10][0] = \'Add Contacts\';
$submenu[\'edit.php\'][15][0] = \'Status\'; // Change name for categories
$submenu[\'edit.php\'][16][0] = \'Labels\'; // Change name for tags
echo \'\';
}
function change_post_object_label() {
global $wp_post_types;
$labels = &$wp_post_types[\'post\']->labels;
$labels->name = \'Contacts\';
$labels->singular_name = \'Contact\';
$labels->add_new = \'Add Contact\';
$labels->add_new_item = \'Add Contact\';
$labels->edit_item = \'Edit Contacts\';
$labels->new_item = \'Contact\';
$labels->view_item = \'View Contact\';
$labels->search_items = \'Search Contacts\';
$labels->not_found = \'No Contacts found\';
$labels->not_found_in_trash = \'No Contacts found in Trash\';
}
add_action( \'init\', \'change_post_object_label\' );
add_action( \'admin_menu\', \'change_post_menu_label\' );
要更改菜单顺序,请执行以下操作:// CUSTOMIZE ADMIN MENU ORDER
function custom_menu_order($menu_ord) {
if (!$menu_ord) return true;
return array(
\'index.php\', // this represents the dashboard link
\'edit.php\', //the posts tab
\'upload.php\', // the media manager
\'edit.php?post_type=page\', //the posts tab
);
}
add_filter(\'custom_menu_order\', \'custom_menu_order\');
add_filter(\'menu_order\', \'custom_menu_order\');
我有删除项目的代码,但它是全局的,不基于用户访问级别要重命名默认的帖子类型(或任何其他类型),只需使用过滤器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 );
我同意。。这个functions.php
文件提供了很大的灵活性。我需要一些与您描述的功能相同的功能functions.php
过滤器和this plugin.
据我所知。。这个插件可以解决您的两个问题,并且在多站点安装情况下也能很好地工作。希望这有帮助。
你可能想看看this question
还有他们提到的课堂gist
其中包含您需要的函数
rename_admin_menu_section()
重命名,例如将帖子更改为文章您可以删除“外观”菜单并为创建新的首页菜单项
上面诺克罗斯的例子是正确的,但我需要国际化的可能性。如果我有这个名声,这将是诺克罗斯回答下的评论,但既然我没有,我就把修改过的代码放在这里。”i18n\\u context是翻译上下文的任意名称空间,例如,它可以是插件或主题的名称。
function change_post_menu_label() {
global $menu;
global $submenu;
$menu[5][0] = __(\'Contacts\', \'i18n_context\');
$submenu[\'edit.php\'][5][0] = __(\'Contacts\', \'i18n_context\');
$submenu[\'edit.php\'][10][0] = __(\'Add Contacts\', \'i18n_context\');
$submenu[\'edit.php\'][15][0] = __(\'Status\', \'i18n_context\'); // Change name for categories
$submenu[\'edit.php\'][16][0] = __(\'Labels\', \'i18n_context\'); // Change name for tags
echo \'\';
}
function change_post_object_label() {
global $wp_post_types;
$labels = &$wp_post_types[\'post\']->labels;
$labels->name = __(\'Contacts\', \'i18n_context\');
$labels->singular_name = __(\'Contact\', \'i18n_context\');
$labels->add_new = __(\'Add Contact\', \'i18n_context\');
$labels->add_new_item = __(\'Add Contact\', \'i18n_context\');
$labels->edit_item = __(\'Edit Contacts\', \'i18n_context\');
$labels->new_item = __(\'Contact\', \'i18n_context\');
$labels->view_item = __(\'View Contact\', \'i18n_context\');
$labels->search_items = __(\'Search Contacts\', \'i18n_context\');
$labels->not_found = __(\'No Contacts found\', \'i18n_context\');
$labels->not_found_in_trash = __(\'No Contacts found in Trash\', \'i18n_context\');
}
add_action( \'init\', \'change_post_object_label\' );
add_action( \'admin_menu\', \'change_post_menu_label\' );
我不想为了改变用户输入新帖子的页面而编辑核心文件,所以有没有一种方法可以在一个主题中,或者在函数中这样做。php。。?具体来说,我正在尝试将“设置特色图像”文本的措辞更改为类似“设置特色图像-50像素乘以50像素”