Add Custom Plugin Settings Links to Your Plugin

Chain Anchor
License: Adobe Stock

Setting links are a great and easy way to provide shortcuts to your users.

Here are a few that I’ve included as part of my plugins.

Simple Comment Editing Setting Links
Simple Comment Editing Setting Links
Highlight and Share Setting links
Highlight and Share Setting links

Starting With Initialization

DLX Plugin Setting Links with Namespace
DLX Plugin Setting Links with Namespace

Let’s start with your main plugin file. I first add in a namespace, simply because prefixing functions is the wild west.

namespace DLXPlugins\DLXPluginSettingLinks;Code language: PHP (php)

Since adding setting links requires a reference to the main plugin file, I usually add a constant which I can reference later.

In the above example, I use the following snippet to create my file reference:

define( 'HIGHLIGHT_AND_SHARE_FILE', __FILE__ );Code language: PHP (php)

This HIGHLIGHT_AND_SHARE_FILE constant will be used to reference my main plugin file. This is extremely useful if you have multiple plugin files that are not in the plugin root.

To keep this simple, we’ll just include everything in the main plugin file. We’ll start by calling a filter so that we can add in our own setting links.

add_filter(
	'plugin_action_links_' . plugin_basename( DLX_PLUGIN_SETTING_LINKS ),
	'DLXPlugins\DLXPluginSettingLinks\add_settings_links'
);Code language: PHP (php)

We start with the prefix plugin_action_links_. After that, append the plugin’s basename and pass it a reference to the main plugin file.

Add a callback called add_settings_links, which we’ll use in the next example. Note that I used the namespace for the callback function.

/**
 * Callback for plugin_action_links
 *
 * @param array $links Array of links.
 *
 * @return array updated links.
 */
function add_settings_links( $links ) {
	$docs_link = '<a href="https://docs.dlxplugins.com" target="_blank">Docs</a>';
	array_push( $links, $docs_link );
	return $links;
}Code language: PHP (php)

You should end up with a new docs setting link, as shown in the screenshot below.

Plugin Setting Links in the Admin Plugins Screen
Plugin Setting Links in the Admin Plugins Screen

If you’d like docs to show up before Deactivate, use array_unshift instead of array_push.

/**
 * Callback for plugin_action_links
 *
 * @param array $links Array of links.
 *
 * @return array updated links.
 */
function add_settings_links( $links ) {
	$docs_link = '<a href="https://docs.dlxplugins.com" target="_blank">Docs</a>';
	//array_push( $links, $docs_link );
	array_unshift( $links, $docs_link );
	return $links;
}Code language: PHP (php)
Docs Before Deactivate in the Plugins Screen
Docs Before Deactivate in the Plugins Screen

Want to add color and formatting? Just add inline styles.

/**
 * Callback for plugin_action_links
 *
 * @param array $links Array of links.
 *
 * @return array updated links.
 */
function add_settings_links( $links ) {
	$docs_link = '<a href="https://docs.dlxplugins.com" target="_blank" style="color: green; font-weight: 600">Docs</a>';
	//array_push( $links, $docs_link );
	array_unshift( $links, $docs_link );
	return $links;
}Code language: PHP (php)
Docs are Green and Bold
Docs are Green and Bold

For multisite, you’d follow the steps above, but instead would use network_admin_plugin_action_links_ as the prefix.

Here’s an example in the wild:

Plugin Setting Links for Multisite
Plugin Setting Links for Multisite

That’s it!

In this short tutorial, I explained how to add setting links, how to adjust the priority, how to customize the appearance, and also how to do it with multisite.

Please leave any questions and I’ll be sure to answer them.

Ronald Huereca
By: Ronald Huereca
Published On: on December 21, 2022

Ronald Huereca founded DLX Plugins in 2022 with the goal of providing deluxe plugins available for download. Find out more about DLX Plugins, check out some tutorials, and check out our plugins.

Leave Your Valuable Feedback

Your email address will not be published. Required fields are marked *

Shopping Cart
  • Your cart is empty.
Scroll to Top