Codeable info

Adding Plugin Action Links

Posted on by in WordPress Tutorials

Plugin action links are the links that appear just below the plugin name in your WP plugins menu, such as “Edit” and “Activate”. Have you ever seen those plugins that have somehow added additional links to that list, such as “Settings” or “Donate”? It’s actually quite simple.

First, we are going to create a function that will display our links.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function our_plugin_action_links($links, $file) {
    static $this_plugin;
 
    if (!$this_plugin) {
        $this_plugin = plugin_basename(__FILE__);
    }
 
    // check to make sure we are on the correct plugin
    if ($file == $this_plugin) {
        // the anchor tag and href to the URL we want. For a "Settings" link, this needs to be the url of your settings page
        $settings_link = 'Settings';
        // add the link to the list
        array_unshift($links, $settings_link);
    }
 
    return $links;
}

This function isn’t overly complex, but it’s not extremely simple either. Basically, we do a check to ensure we’re on the right plugin, then we provide a little HTML (the anchor tag) for our link, and then, finally, we add the new link to the list of existing links.

Next, we just need to run our function through a filter, which will make out link actually appear.

1
add_filter('plugin_action_links', 'our_plugin_action_links', 10, 2);

And the result should look something like this:

Enjoy!

)
Codeable info

Comments (4)

Comment by auntypizza says:

Nice post … I have got the link appearing but now what.
Obviously when I click on the Settings link nothing will happen (although I get “You do not have sufficient permissions to access this page.”)
 
Can you continue this post explaining how to actually add the settings CONTENTS.
That would be great.
 
I have scoured the net for hours looking for help with this but nothing so far.

Comment by Daniel says:

Thanks for the info! This site is very nice – will save it.

Comment by Pippin Williamson says:

Great, glad it was helpful.

Comment by Dalton says:

Thanks, this is a nice tip and something I’ve been wanting to add to my plugins.

Codeable info