Adding Plugin Action Links

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!

This article was authored by:

Pippin Williamson is a WordPress developer based in Lawrence, KS. WordPress is his expertise: custom theme / plugin development, e-commerce solutions, content management, and everything else WordPress. His personal site can be found at PippinsPlugins.com. There he publishes frequent WordPress tutorials, tips and tricks. He also host a variety of his own free WordPress plugins. Join the site and receive member only benefits, including exclusive tutorial access and source file downloads.

Pippin Williamson has authored 42 posts.Visit Website

Showing 4 Comments

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

    REPLY
  • Pippin (Admin)

    Great, glad it was helpful.

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

    REPLY
  • auntypizza

    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.

    REPLY

Add Your Voice: