Adding Plugin Action Links

Written by on March 11, 2011 in WordPress Tutorials - 3 Comments

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 = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=font-uploader.php">Settings</a>';
        // 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!

About

Pippin Williamson is an expert WordPress dev with 4+ years of experience. You may follow him on Twitter @pippinspages and @pippinsplugins and see his free WP plugins, themes, and tutorials he has to offer at Pippin's Pages.com and Pippin's Plugins.com

Post comment as twitter logo facebook logo
Sort: Newest | Oldest

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

Great, glad it was helpful.

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