Add action links to your plugin

What are action links?
Action links are the additional menu items under your plugin’s name on the plugins.php page. By default, you’ll always see Active/Deactivate there and, if you’re not on multisite, you’ll also see the option to delete a plugin.
What action links should I add?
I think it’s really helpful to give the user some additional choices when they start using your plugin, especially from the same menu they used to activate it. Here are a few options you could use.
- Add a ‘Settings’ link: sometimes users can cast around looking for your Settings page so placing a ‘Settings’ menu item here is ideal. On the Discussion Board plugin, the Settings page is a submenu page of the main Discussion Board menu. I don’t want anyone to find it difficult to locate so I’ve added a Settings link that’s visible to the user as soon as they activate the plugin from the
plugins.php
page. - Add a ‘Support’ link: another advantage of having additional links here is that they appear right next to the ‘Deactivate’ link. So if the user has decided not to continue with your plugin, you have one last chance to catch their attention here before they deactivate. So it’s a great place to add a link to your support page.
- Add an ‘Upgrade’ link: You can also provide a direct link to a premium version of your plugin, if you have one. This will encourage users to purchase the upgrade.
Adding the action links
Adding the action links is really straightforward. This is the code from the Discussion Board plugin. You can modify this for your own plugin:
function filter_action_links( $links ) { $links['settings'] = '<a href="' . admin_url( 'edit.php?post_type=discussion-topics&page=discussion_board' ) . '">' . __( 'Settings', 'wp-discussion-board' ) . '</a>'; $links['support'] = '<a href="https://pluginrepublic.com/support">' . __( 'Support', 'wp-discussion-board' ) . '</a>'; // Check to see if Pro version already installed if( class_exists( 'CT_DB_Pro_Admin' ) ) { $links['upgrade'] = '<a href="https://discussionboard.pro">' . __( 'Upgrade', 'wp-discussion-board' ) . '</a>'; } return $links; } add_filter( 'plugin_action_links_wp-discussion-board/wp-discussion-board.php', 'filter_action_links', 10, 1 );
The code makes use of the plugin_action_links_(plugin_file_name)
filter. You can find some documentation here. To find the file name of your plugin, you can insert this code in your main plugin file:
$plugin_file_name = basename( __FILE__ );
Your plugin basename is the name of your plugin’s main file and will now be stored in the $plugin_file_name
variable.
Adding the Settings link
The filter passes the $links
array in. All you need to do is add elements to this array. The first action link I wanted to add was to the ‘Settings’ page:
$links['settings'] = '<a href="' . admin_url( 'edit.php?post_type=discussion-topics&page=discussion_board' ) . '">' . __( 'Settings', 'wp-discussion-board' ) . '</a>';
I created a new element in the $links
array with the settings
key and a link to the Settings page as its value;
Adding a Support link
Using the same method, I created a support element with a link to the support page as the value.
Adding an Upgrade link
The only difference with the upgrade link is that it checks whether the premium version of the plugin is already installed. This isn’t strictly necessary but I think it’s a nice touch to remove the ‘upgrade’ option once the user has upgraded.
I use the class_exists
method to check whether a plugin is installed or not.
Tools for plugin developers
If you’re a plugin developer and you’d like a better way to track how your plugins are being used, please check out the Wisdom plugin, which allows you to gather all kinds of data from your plugins after they’ve been activated on users’ sites.