When building a plugin that has its own settings page, it’s often handy to create a link to the settings page straight from the Plugins list – this saves users the time it takes to find where exactly your plugin appears in the admin menu. Here is a simple code snippet that creates the settings link for you – all you need to do is tell it where to go:
<?php | |
function plugin_add_settings_link( $links ) { | |
$settings_link = '<a href="options-general.php?page=plugin_name">' . __( 'Settings' ) . '</a>'; | |
array_push( $links, $settings_link ); | |
return $links; | |
} | |
$plugin = plugin_basename( __FILE__ ); | |
add_filter( "plugin_action_links_$plugin", 'plugin_add_settings_link' ); | |
?> |
Simply replace the href
attribute with the link to the plugin settings page and rename the function to something slightly more unique (preferably all wrapped in an if(!function_exists())
conditional).
Thanks for the useful tip,
Thanks for the nice post.
however i recommend this little change to make Settings as the first link
array_unshift($links, $settings_link);
Nice tips, save time for me
Hi: I really appreciate this post. It will allow me to (optionally) remove one page from the Admin menu, however, when I click the link, I get the “You do not have sufficient permissions to access this page” message. Any idea what would cause this?
@Dennis_Hall This happens when you have an invalid url
Hugh, I’ve been trying to figure this out forever now and kept putting it on the back burner because I was getting frustrated trying to Frankenstein code in from other plugins. You’re my hero.
Always nice to be someone’s hero :p
Thanks
Thanks. So Good.
I couldn’t refrain from ϲommenting. Well written!