Web dev hints, tips and tricks to help you become an expert.

If you’re developing a WordPress plugin, you may want to add additional links to the Installed Plugins page, in the relevant row of the Plugins list table.

When a plugin is activated, generally by default a ‘Deactivate’ action link will be shown alongside meta links such as ‘Visit plugin site’ or ‘View details’ and the author.

These links are related to the header for each WordPress plugin.

But some developers choose to add additional links to the Installed Plugins page, commonly ‘Settings’ or ‘Upgrade’ action links and/or a ‘Support’ meta link.

Doing so is simple.

The AMP plugin for WordPress adds additional links to the Installed Plugins page, in the Plugins list table
The AMP plugin adds a ‘Settings’ action link and several meta links

Add action links for a plugin in the Plugins list table

Using the plugin_action_links_{$plugin_file} hook, you can filter the list of action links displayed for your plugin in the Plugins list table:

if ( ! function_exists( 'myplugin_add_plugin_action_links' ) ) {
	
	add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'myplugin_add_plugin_action_links' );

	function myplugin_add_plugin_action_links( $actions ) {
		
		$actions[] = '<a href="' . menu_page_url( 'myplugin-settings', false ) . '">' . esc_html__( 'Settings', 'my-plugin' ) . '</a>';
		
		return $actions;
		
	}

}

In the example above we’ve added a link to the ‘Settings’ screen in the plugin.

Using this hook, you can easily add anything to the array of plugin action links.

Add meta links for a plugin in the Plugins list table

You can use the plugin_row_meta hook to filter the array of row meta for each plugin in the Plugins list table.

First confirm you’re filtering the row for your plugin and then add a link to the array of row meta in a similar fashion:

if ( ! function_exists( 'myplugin_add_plugin_meta_links' ) ) {
	
	add_filter( 'plugin_row_meta', 'myplugin_add_plugin_meta_links' );
	
	function myplugin_add_plugin_meta_links( $plugin_meta, $plugin_file ) {
		
		if ( plugin_basename( __FILE__ ) == $plugin_file ) {
			
			$plugin_meta[] = sprintf( __( '<a href="%s">Support</a>', 'my-plugin' ), '#' );
			
		}
		
		return $plugin_meta;
		
	}

}

Both of the above code snippets append your additional links to the row of existing ones. To prepend the links, use array_unshift.

Leave a Reply

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