Adding a Settings link to your plugin on the Plugin admin screen adds a bit of polish to your plugin. You’ve probably noticed many plugins include a Settings link right next to Deactivate and Edit. This is an easy feature to add.
These Settings links are particularly nice due to the variability in settings page locations within the WordPress menu. You’ll find settings pages under Settings, Tools, Dashboard, Media, Users, and Custom Top Level Menu Items. It can be very frustrating as a user seeking out the settings page, especially when the menu label does not match the plugin name.
How to Use This Code Snippet
- Paste this code into the main plugin file (it can not be an include or require file within the plugin)
- Modify
options-general.php?page=my-plugin
to match the URL ending for your settings page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'salcode_add_plugin_page_settings_link'); | |
function salcode_add_plugin_page_settings_link( $links ) { | |
$links[] = '<a href="' . | |
admin_url( 'options-general.php?page=my-plugin' ) . | |
'">' . __('Settings') . '</a>'; | |
return $links; | |
} |
Thanks a lot!!!!!!!!! you save my day 🙂
Short and to the point.
Simple, Clean and usefull.
you made my day 🙂
Rather than “adds a bit of polish”, I wish this was a requirement of ALL plugins. Either the link to settings, or say there are none. So much time wasted trawling through the admin menu…
Hi,
It didn’t work for me until I changed the admin url to
admin_url( 'admin.php?page=vw-postcode-checker' )
instead of
options-general.php
But apart from that great tutorial. QUick and to the point.
THank you
I’m glad this was helpful.
I believe the URL is
admin.php
for top level menu items andoptions-general.php
for sub-menu items found under the top-levelSettings
menu item.Clearly, there are exceptions to any rule (and I don’t know anything about your specific use-case) however as a rule I try to always put my settings in the sub-menu.
Sal, I’m wondering if you could share code related to removing the settings link if the plugin is deactivated? In my plugin, I have 2 very specific functions (activate and deactivate) that have a triggered sequence of events. I’d like to CREATE the link during activation and REMOVE the link during deactivation.
how to change the position of the menu item.
For example, on my side it appeared like:
Deactivate | Settings
but for other plugins, it’s as shown below
Settings | Deactivate
probably “Settings | Deactivate”, comes with a better user experience(UX). Please let me know if there is away to make the arrangement of my links like the other plugins
thanks
Hi Benson,
In the
salcode_add_plugin_page_settings_link()
function we are appending the new link to end of the$links
array with the code$links[] =
.If we want to prepend the link and add it to the beginning of the array, you may be able to use array_unshift() instead (note: I’ve not tried this yet but it is where I would start).
array_unshift
worked for me! New function would look like:Thanks a lot!!! You Saved Me a lot of time a effort