Skip to content

Instantly share code, notes, and snippets.

@codeclinic
Created December 17, 2018 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeclinic/d432389e7d67f1a1fb73891feaa1d6fb to your computer and use it in GitHub Desktop.
Save codeclinic/d432389e7d67f1a1fb73891feaa1d6fb to your computer and use it in GitHub Desktop.
WordPress Admin Menu: External link with Icon
function add_custom_menu_item(){
add_menu_page( 'Menu Item Title', 'Page Title', 'manage_options', 'page_slug', 'function', 'dashicons-icon', 1 );
}
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('/my-page') );
exit();
}
}
add_action( 'admin_init', 'custom_menu_item_redirect', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment