Cách thêm menu tùy chỉnh trong bảng điều khiển quản trị viên WordPress

Hãy xem cách thêm các mục menu quản trị tùy chỉnh trong WordPress. Ngoài ra, tôi sẽ chỉ cho bạn cách thêm các mục menu quản trị tùy chỉnh trên thanh quản trị WordPress. Đó không phải là một nhiệm vụ khó khăn và sẽ chỉ mất vài phút để hoàn thành

Mục lục

Băng hình. Làm cách nào để thêm các mục menu quản trị viên tùy chỉnh trong WordPress?

Có lẽ bạn sẽ dễ dàng làm theo hướng dẫn hơn một chút sau khi xem video hướng dẫn này mà tôi đã thực hiện về cùng chủ đề

Làm cách nào để thêm các mục menu thanh quản trị tùy chỉnh?

Trước tiên, tôi sẽ chỉ cho bạn cách thêm các mục menu của thanh quản trị tùy chỉnh. Chỉ cần lấy mã này ở đây bên dưới và thêm nó vào trong các chức năng của chủ đề con bạn. php hoặc tốt hơn nữa, hãy sử dụng plugin Code Snippets cho nó. Ngoài ra, hãy xem các nhận xét bên trong mã để xem cái gì là cái gì

// First level menu
add_action['admin_bar_menu', 'add_toolbar_items', 100];
function add_toolbar_items[$admin_bar]{
	$admin_bar->add_menu[ array[
		'id'    => 'my-item',
		'title' => 'All tutorials', // Your menu title
		'href'  => '//know.local/', // URL
		'meta'  => array[
		 'target' => '_blank',
		],
	]];

  // Submenus
	$admin_bar->add_menu[ array[
		'parent' => 'my-item',
		'title' => 'Remove admin menus', // Your submenu title
		'href'  => '//wpsimplehacks.com/how-to-remove-wordpress-admin-menu-items/', // URL
		'meta'  => array[
		'target' => '_blank',
		],
	]];
		$admin_bar->add_menu[ array[
		'parent' => 'my-item',
		'title' => 'Custom Admin Dashboard',
		'href'  => '//wpsimplehacks.com/how-to-create-custom-wordpress-admin-dashboard/',
		'meta'  => array[
		'target' => '_blank',
		],
	]];  
	$admin_bar->add_menu[ array[
		'parent' => 'my-item',
		'title' => 'Block Patterns',
		'href'  => '//wpsimplehacks.com/how-to-create-wordpress-block-patterns-and-reusable-blocks/',
		'meta'  => array[
		'target' => '_blank',
		],
	]];
}
}

Nếu bạn muốn xóa các mục trong menu con, hãy chọn phần này và xóa nó

	$admin_bar->add_menu[ array[
		'parent' => 'my-item',
		'title' => 'Block Patterns',
		'href'  => '//wpsimplehacks.com/how-to-create-wordpress-block-patterns-and-reusable-blocks/',
		'meta'  => array[
		'target' => '_blank',
		],
	]];

Điều tương tự nếu bạn muốn thêm menu con – chỉ cần lấy phần này ở trên đây và dán nó bên dưới mã mục menu con trước đó

Làm cách nào để thêm các mục menu quản trị tùy chỉnh?

Bây giờ, hãy xem cách thêm các mục menu quản trị viên tùy chỉnh trong WordPress

Một lần nữa, hãy lấy một đoạn mã ở đây bên dưới và cho chúng tôi biết liệu bên trong các chức năng của chủ đề con bạn. php hoặc bên trong hộp mã Code Snippets

add_action['admin_menu', 'admin_menu_add_external_links_as_submenu'];
add_action[ 'admin_head', 'admin_menu_add_external_links_as_submenu_jquery' ];

function admin_menu_add_external_links_as_submenu[] {
    global $submenu;

    $menu_slug = "externallink"; // used as "key" in menus
    $menu_pos = 2; // whatever position you want your menu to appear

    // create the top level menu
    add_menu_page[ 'external_link', 'How-to...', 'read', $menu_slug, '', '', $menu_pos];

    // add the external links to the slug you used when adding the top level menu
    $submenu[$menu_slug][] = array['
...create CPT
'
, 'manage_options', '//wpsimplehacks.com/how-to-create-custom-post-type-in-wordpress-without-a-plugin-within-couple-of-minutes/'];
$submenu[$menu_slug][] = array['
...use Blocks
'
, 'manage_options', '//wpsimplehacks.com/how-to-use-blocksy-content-blocks-hooks-full-tutorial/'];
$submenu[$menu_slug][] = array['
...get discounts
'
, 'manage_options', '//wpsimplehacks.com/start-here/'];
function admin_menu_add_external_links_as_submenu_jquery[] { ?> jQuery[document].ready[ function[$] { $['#newtab1'].parent[].attr['target','_blank']; $['#newtab2'].parent[].attr['target','_blank']; $['#newtab3'].parent[].attr['target','_blank']; }];

Chủ Đề