問題描述
我已經花了最後一天使用 functions.php 檔案來為我的客戶端網站完全自定義 WordPress 。我感到驚訝的是,我能夠完成多少工作,併為我的客戶帶來多少容易。
我已經刪除了沒有以管理員身份登入的使用者的某些選單項。我希望 (從我所看到的知道它可以做到) 是找到一種方法來重新命名一些選單項 (管理區域中的左側欄) 。例如將帖子更改為文章。
如果有人可以提供的程式碼為 functions.php 檔案或指向我的方向我會非常感謝它!
最佳解決方案
以下是更改標籤的過程 (我在示例中將帖子更改為”contacts”)
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');
我有程式碼來刪除專案,但它是全域性而不是基於使用者訪問級別
次佳解決方案
你可能想看看 this question
和他們在 gist 上提到的課程
它擁有你所尋找的功能
rename_admin_menu_section()
重新命名,例如將帖子更改為文章
您可以刪除外觀選單,併為您建立新的首頁選單項
第三種解決方案
我同意.. functions.php 檔案提供了很多的靈活性。我需要一些與 functions.php 過濾器和 this plugin 組合使用的相同功能。
從我可以告訴這個外掛將完成您的兩個問題,它也可以在 Multi-Site 安裝情況下執行良好。希望有幫助。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。