WordPress: Add Your Plugin’s Settings Link to Admin Plugins Page

Hello, WordPress plugin authors!  I’ve been envious of that little “Settings” link on the Plugins page in the Admin on several of the plugins I use on my blogs.  I wanted one for my own PhotoSmash plugin!

My first stop, Google, yielded no fruit, but persistence paid off.  So, thanks to GD-Star Ratings and Shadowbox-JS, I finally figured it out!

And now, for your coding pleasure, here’s the step-by-step:

Steps for Showing Settings Link

1. Add a function that injects your link into the links array.  The array_unshift adds your link to the front of the array.  The $this_plugin wizardry is determining whether this instance of the filter is being called for your plugin or another one.  You only want to add the link to your plugin ;-).  Here’s the code:

 * Add Settings link to plugins - code from GD Star Ratings
 function add_settings_link($links, $file) {
static $this_plugin;
if (!$this_plugin) $this_plugin = plugin_basename(__FILE__);

if ($file == $this_plugin){
$settings_link = '<a href="admin.php?page=bwb-photosmash.php">'.__("Settings", "photosmash-galleries").'</a>';
 array_unshift($links, $settings_link);
return $links;

Of course, you’ll need to change the page link as appropriate.  The easiest way to get that is to go to your plugin’s settings page and copy it from the URL.  You want everything after the last forward slash “/”. Screenshot!

2. Add a filter for the plugin_action_links filter. When the Plugins page is displayed in Admin, this filter will pass your function the links array.  Here’s the code:

add_filter('plugin_action_links', array(&$bwbPS, 'add_settings_link'), 10, 2 );

Note this part:  array(&$bwbPS, ‘add_settings_link’)

If you’re putting your function inside a class, you need to use an array as a parameter, with your plugin’s instance variable…mine is $bwbPS.  The “&” in front of the instance variable tells it to use the instance by reference (which I believe is automatic for objects anyway, but just do it 😉 ).  The part after the ‘,’ is the function name we’re calling.  You can name it whatever you like.

If you’re not placing your function inside a class, then you’re code will look like:

add_filter('plugin_action_links', 'add_settings_link', 10, 2 );

But you’re going to want to make sure your function name is totally unique in the whole WordPress world.  Otherwise, POW!  Namespace collision.

Hope that helps!  It’s easy, and it’s so very helpful to have that link there.  I just love a plugin that has it because I don’t have to search for it in the sidebar, and secondly, I figure that the coder must know what he/she’s doing 😛



, ,

2 Responses to WordPress: Add Your Plugin’s Settings Link to Admin Plugins Page

  1. Paul July 19, 2010 at 10:57 pm #

    Hi Byron

    I apologise for leaving a comment here but I couldn’t find a contact method on the site.

    I am currently using supple forms as a way to improve the consistency of one of my websites that is being updated by a team. Fits of all I’d like to say that its working really well and I thank you for your work to create the plugin. However I am now trying to generate some simple reports based off of the table (group by’s) that supple forms creates. Have you ever done this? I guess you have no ideas to add this functionality to the form? If not would you recommend any software for this.

    Keep up the good work!


  2. Mahmud Ahsan August 31, 2011 at 7:23 pm #

    Thanks for the tips. Helpful.

Powered by WordPress. Designed by Woo Themes