Categories
PHP

Add a Link to Your Plugin from the WordPress Plugin List

There’s nothing more annoying than installing a new WordPress plugin and having to dig around the WordPress admin menu to figure out where the plugin lives. In this post, you’ll learn how to add a link to your plugin page from the plugin list.

1

There’s nothing more annoying than installing a new WordPress plugin and having to dig around the WordPress admin menu to figure out where the plugin lives. Is it a new top level page? No. In the settings menu? No chance. Then where?

You can improve the onboarding experience for new plugin users by including a link to your plugins dashboard or settings page right inside the plugin list. 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.

add_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.

function add_plugin_action_link($links)
{
    // Build the URL
    $url = add_query_arg('page', 'independent-analytics', admin_url('admin.php'));

    // Create the link
    $settings_link = '<a class="calendar-link" href="' . esc_url($url) . '">' . esc_html__('Analytics Dashboard', 'iawp') . '</a>';

    // Link first: Having the link show up as the first link
    array_unshift($links, $settings_link);

    // Link last: Having the link show up as the last link
    // array_unshift($links, $settings_link);

    // Return the modified $links array
    return $links;
}

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.

1