I'm trying to add top level menu items (not sub-menus) to my WP admin menu that link to edit a post. The reason for it, is that I have different sections and custom post types, so I'd like to have items in the menu that work like shortcuts.
So far I was able to create one using the code below, which isn't mine, but I adapted it. It works fine for just one item, but I'd like to create more (two or three) and I haven't been able to get it right.
function add_custom_menu_item(){
add_menu_page( 'Slider Menu', 'Slider', 'manage_options', 'page_slug', 'function', 'dashicons-images-alt2', 6 );
}
add_action( 'admin_menu', 'add_custom_menu_item' );
function custom_menu_item_redirect() {
$menu_redirect = isset($_GET['page']) ? $_GET['page'] : false;
if($menu_redirect == 'page_slug' ) {
wp_safe_redirect( home_url('/wp-admin/post.php?post=1883&action=elementor') );
exit();
}
}
add_action( 'admin_init', 'custom_menu_item_redirect', 1 );
I'd appreciate any help.
Thanks.
add_menu_page()
line for the other top-level links you want to create. See developer.wordpress.org/reference/functions/add_menu_pageadd_menu_page()
line allows me to create more top level items. What I don't know is how to add different redirects to each one of them.