Everything about plugin_action_links and plugin_row_meta

Simple but useful hooks for WordPress developers. When I needed these hooks for my plugins, I couldn’t find any good tutorials, so I decided to create the one.

/7 comments

Look at this screenshot:

plugin_action_links and plugin_row_meta filters example
By the way, if the plugin on the screenshot seems interesting for you, find out more on this page.

The key idea is very simple — if you want to add some links under the plugin name, use plugin_action_links filter hook (or network_admin_plugin_action_links for WordPress Multisite), if you would like to add something under a plugin description, plugin_row_meta will help you.

Let’s try to add the settings link now. The only thing you should know about plugin_action_links and plugin_row_meta is that these hooks are fired for every installed plugin! 😁

So you have to perform some conditional checks, and there are two ways to do it.

1. Check if it is the plugin you need inside the function

add_filter( 'plugin_action_links', 'misha_settings_link', 10, 2 );
 
function misha_settings_link( $links_array, $plugin_file_name ){
	// $plugin_file_name is plugin-folder/plugin-name.php
 
	// if you use this action hook inside main plugin file, use basename(__FILE__) to check
	if( strpos( $plugin_file_name, basename(__FILE__) ) ) {
		// we can add one more array element at the beginning with array_unshift()
		array_unshift( $links_array, '<a href="#">Settings</a>' );
	}
 
	return $links_array;
}

2. plugin_action_links_plugin-name/plugin-name.php

But you can skip the part of the code with condition, just add the plugin file name to the hook.

add_filter( 'plugin_action_links_plugin-name/plugin-name.php', 'misha_settings_link' );
 
function misha_settings_link( $links_array ){
	array_unshift( $links_array, '<a href="#">Settings</a>' );
	return $links_array;
}

The result:

Example of using plugin_action_links filter
Settings link is added with the help of plugin_action_links filter hook.

There is not so much to say. Just if you’re running a WordPress Multisite network and if you want to add plugin action links to the Network Dashboard plugin page, use:

More hook parameters

No matter which of the above hooks you use, all of them have the same parameters, example:

add_filter( 'plugin_action_links', 'misha_settings_link', 10, 4 );
 
function misha_settings_link( $links_array, $plugin_file_name, $plugin_data, $context ){
 
	...

Everything should be clear with $links_array and $plugin_file_name but what about the rest?

$plugin_data
(Array) Contains all the plugin meta information, like Name, Description, Author, AuthorURI etc.
$context
(String) The plugin status. It can include by default: ‘all’, ‘active’, ‘recently_activated’, ‘inactive’, ‘upgrade’, ‘dropins’, ‘mustuse’, and ‘search’.

plugin_row_meta

Well, it is sad, but plugin_row_meta doesn’t have a hook with plugin file name in it. So, you must use a condition. Let’s add FAQ, Support and Check for updates links with its help.

add_filter( 'plugin_row_meta', 'misha_support_and_faq_links', 10, 4 );
 
function misha_support_and_faq_links( $links_array, $plugin_file_name, $plugin_data, $status ){
 
	if( strpos( $plugin_file_name, basename(__FILE__) ) {
		// you can still use array_unshift() to add links at the beginning
		$links_array[] = '<a href="#">FAQ</a>';
		$links_array[] = '<a href="#">Support</a>';
		$links_array[] = '<a href="#">Check for updates</a>';
	}
 
	return $links_array;
}

Result:

Add three more links with WordPress plugin_row_meta filter.
FAQ, Support and Check for updates links are added with the help of plugin_row_meta.

More stuff about creating plugins

Misha Rudrastyh

Misha Rudrastyh

I love WordPress, WooCommerce and Gutenberg so much. 10 yrs of experience.

Need some custom developer help? Let me know

Follow Misha

Need some help with WordPress Multisite?

If you need some professional developer help, I will be happy to assist you.

Contact me Who I am?

Comments — 7

Leave a comment

php js HTML CSS Code