Add settings link under plugin name

When creating a custom plugin, you may want to add a custom link to the setting page. That way, the plugin users don’t have to search for the link in the sidebar. An easy way to do this is to add the following snippet in the main file of your plugin.

add_action( 'plugin_action_links_' . plugin_basename( __FILE__ ), function ( $links ): array {
    $label = esc_html__( 'Settings', 'text-domain' );
    $slug  = 'your-page-slug;

    array_unshift( $links, "<a href='admin.php?page=$slug'>$label</a>" );

    return $links;
}, 10 );

Now you must replace the your-page-slug string with that one that you used when registering the custom admin page. That’s the $menu_slug from add_submenu_page.

Also you may want to replace the admin.php, but from my experience, this works OK. Just doesn’t highlight the active link in the sidebar.

Easy tip: Copy the page suffix after wp-admin/ when you are on your plugin’s settings page.

Member since January 2, 2019

Fullstack Web Developer with more than 12 years of experience in web development. Adept in all stages of advanced web development. Knowledgeable in the user interface, backend, testing, and debugging processes. Bringing forth expertise in design, installation, testing, and maintenance of web systems. Working exclusively and professionally with WordPress since 2010.


    Your email address will not be published. Required fields are marked *