25% off ProSNIPC25OFF

Add a Custom Admin Menu Link

Adds a top-level admin sidebar item that redirects to an external URL such as documentation or a project management tool.

PHPby SnipCraft
php
<?php
// Change SCSEED_DOCS_URL to the destination you want the menu item to open.
if ( ! defined( 'SCSEED_DOCS_URL' ) ) {
    define( 'SCSEED_DOCS_URL', 'https://example.com/docs' );
}

add_action( 'admin_menu', 'scseed_add_admin_menu_link' );
if ( ! function_exists( 'scseed_add_admin_menu_link' ) ) {
    function scseed_add_admin_menu_link() {
        add_menu_page(
            __( 'Documentation', 'scseed' ),
            __( 'Documentation', 'scseed' ),
            'read',
            'scseed_admin_docs',
            'scseed_admin_docs_page',
            'dashicons-book-alt',
            99
        );
    }
}

if ( ! function_exists( 'scseed_admin_docs_page' ) ) {
    function scseed_admin_docs_page() {
        // Intentionally empty — redirect fires via admin_init below.
    }
}

add_action( 'admin_init', 'scseed_redirect_admin_menu_link' );
if ( ! function_exists( 'scseed_redirect_admin_menu_link' ) ) {
    function scseed_redirect_admin_menu_link() {
        $page = isset( $_GET['page'] ) ? sanitize_key( $_GET['page'] ) : '';
        if ( 'scseed_admin_docs' === $page ) {
            wp_redirect( SCSEED_DOCS_URL );
            exit;
        }
    }
}
#admin#menu#navigation#settings#ux