There’s nothing more annoying than installing a new plugin and being forced to dig around the admin menus to figure out where it lives. Why not improve your WordPress plugin onboarding by adding a link directly to your plugins page?
As an example, the screenshot below shows the “Analytics Dashboard” link I added for Independent Analytics.
Adding a link requires you to use the plugin_action_links
filter. You’ll need to call add_filter
with two arguments. The first argument is the filter name, and the second argument is a callback function to run.
The filter name should start with plugin_action_link
followed by the path to your plugin file. This includes your plugins folder name as well as your plugins main file name (the one with the header comment).
For Independent Analytics that would be independent-analtyics/iawp.php
.
1add_filter('plugin_action_links_independent-analytics/iawp.php', 'add_plugin_action_link');
The callback function gets called with a single argument, an array of the current links. The callbacks job is to add new links to the array and then return the modified array. You can add links to the beginning of the array to have them show up first or onto the end of the array to have them show up last.
1function add_plugin_action_link($links) 2{ 3 // Build the URL 4 $url = add_query_arg('page', 'independent-analytics', admin_url('admin.php')); 5 6 // Create the link 7 $settings_link = '<a class="calendar-link" href="' . esc_url($url) . '">' . esc_html__('Analytics Dashboard', 'iawp') . '</a>'; 8 9 // Link first: Having the link show up as the first link10 array_unshift($links, $settings_link);11 12 // Link last: Having the link show up as the last link13 // array_push($links, $settings_link);14 15 // Return the modified $links array16 return $links;17}
That’s all there is to it. You can add as many links as you like, though one or two should be more than enough.