WordPress
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.
Back to Home
Share:
Comments
Share your thoughts and join the conversation
No comments yet
Be the first to share your thoughts!
Failed to load comments
Please try refreshing the page
Leave a Comment