WordPress Backend Titel in linker Adminleiste
Achtung: WIP. Erstellen von 6 verschiedenen Platzhaltern.
PHP
<?php
function add_custom_admin_menu_titles() {
global $menu;
// Define multiple titles with the custom class "title-separator"
$custom_titles = array(
array(
'', // No link
'read', // Capability required (e.g., 'manage_options')
'separator-1', // Slug (just a unique identifier, won't be used)
'First Title', // The title to display
'', // Icon (none needed here)
'title-separator' // Custom CSS class
),
array(
'', // No link
'read', // Capability required (e.g., 'manage_options')
'separator-2', // Slug (just a unique identifier, won't be used)
'Second Title', // The title to display
'', // Icon (none needed here)
'title-separator' // Custom CSS class
),
array(
'', // No link
'read', // Capability required (e.g., 'manage_options')
'separator-3', // Slug (just a unique identifier, won't be used)
'Third Title', // The title to display
'', // Icon (none needed here)
'title-separator' // Custom CSS class
),
array(
'', // No link
'read', // Capability required (e.g., 'manage_options')
'separator-4', // Slug (just a unique identifier, won't be used)
'Fourth Title', // The title to display
'', // Icon (none needed here)
'title-separator' // Custom CSS class
),
array(
'', // No link
'read', // Capability required (e.g., 'manage_options')
'separator-5', // Slug (just a unique identifier, won't be used)
'Fifth Title', // The title to display
'', // Icon (none needed here)
'title-separator' // Custom CSS class
),
array(
'', // No link
'read', // Capability required (e.g., 'manage_options')
'separator-6', // Slug (just a unique identifier, won't be used)
'Sixt Title', // The title to display
'', // Icon (none needed here)
'title-separator' // Custom CSS class
)
);
// Insert each title as its own menu item
foreach ($custom_titles as $index => $title) {
// Use `add_menu_page` for each title, to add them as top-level menu items
add_menu_page(
$title[3], // Page title (won't be used, no link)
$title[3], // Menu title (what's shown in the sidebar)
$title[1], // Capability required
$title[2], // Slug (unique identifier, but no link)
'', // No function callback (no link)
'', // No icon
2 + $index // Position in the menu (adjust as necessary)
);
}
}
add_action('admin_menu', 'add_custom_admin_menu_titles');
Sass
.toplevel_page_separator-1 .wp-menu-name,
.toplevel_page_separator-2 .wp-menu-name,
.toplevel_page_separator-3 .wp-menu-name,
.toplevel_page_separator-4 .wp-menu-name,
.toplevel_page_separator-5 .wp-menu-name,
.toplevel_page_separator-6 .wp-menu-name {
padding-left: 11px !important;
font-weight: 600 !important;
font-size: 1rem !important;
}
.toplevel_page_separator-1 .wp-menu-name::after,
.toplevel_page_separator-2 .wp-menu-name::after,
.toplevel_page_separator-3 .wp-menu-name::after,
.toplevel_page_separator-4 .wp-menu-name::after,
.toplevel_page_separator-5 .wp-menu-name::after,
.toplevel_page_separator-6 .wp-menu-name::after {
content: "";
position: absolute;
bottom: 4px;
left: 10px;
width: 80%;
height: 1px;
background-color: white;
}
.toplevel_page_separator-1,
.toplevel_page_separator-2,
.toplevel_page_separator-3,
.toplevel_page_separator-4,
.toplevel_page_separator-5,
.toplevel_page_separator-6 {
pointer-events: none !important;
}
.toplevel_page_separator-1 div.wp-menu-image,
.toplevel_page_separator-2 div.wp-menu-image,
.toplevel_page_separator-3 div.wp-menu-image,
.toplevel_page_separator-4 div.wp-menu-image,
.toplevel_page_separator-5 div.wp-menu-image,
.toplevel_page_separator-6 div.wp-menu-image {
display: none !important;
}