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

As a seasoned WordPress developer with expertise in various tech stacks and languages, I bring years of experience to every project I handle. My passion for coding and dedication to delivering exceptional work ensures that each project I take on is of the highest quality. I specialize in creating custom themes, developing plugins, and building full-scale web systems. By staying up-to-date with the latest industry trends and best practices, I incorporate cutting-edge solutions into my work.

Comments

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