Add a Custom Admin Menu Item in WordPress That Redirects to a Specific Page

This code snippet adds a custom menu item labeled “My Account” to the WordPress admin sidebar and redirects the user to a specific page on the frontend if the user clicks on the “My Account” menu item. This can be useful if you want to provide quick access to specific pages (like an account page) directly from the admin dashboard.

function ts_add_custom_menu_item(){
      add_menu_page('Menu Item Title', 'My Account', 'manage_options','page_slug', 'function', 'dashicons-icon', 1);

}
add_action('admin_menu', 'ts_add_custom_menu_item');
function ts_custom_menu_item_redirect(){
$menu_redirect = isset($_GET['page'])? $_GET['page']: false;

if($menu_redirect == 'page_slug'){
wp_safe_redirect(home_url('/my-account'));
exit();
}
}
add_action('admin_init', 'ts_custom_menu_item_redirect',1);