In the list of installed plugins on the WordPress admin area you can find links under the plugin’s name at the left (Deactivate, Edit), and other links under the plugins description at the right next to other information like the version of the plugin (By The Author, View Details).

default_action_links

The links you see in the screenshot above these lines are the default ones displayed by WordPress, except the author’s link that is provided in the plugin main file where we enter all the details like Plugin Name, Description, Version, Author, Author URI…

Not long ago I published a very simple snippet to add action links under the plugin’s name, like a Settings or a FAQ link (or both). But with this snippet you can only add the links at the end of the already existing ones.

Maybe what you want is to display additional links and be able to choose if you want them at the beginning or at the end of the default ones. And you also may want to display additional links on the right hand side just under the plugin’s description.

There are two different filters available to do this, plugin_action_links to add links under the plugin’s name and plugin_row_meta to add links under the plugin’s description.

additional_action_links

So the following code we will see how to use plugin_action_links and plugin_row_meta filters. The functions my_add_action_links and my_plugin_row_meta basically would do the same thing, so I created a third function plugin_action_links that will be called by the two first ones, where you can pass as arguments an array of the links to display and the position of these links (before or after the default ones).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
add_filter( 'plugin_action_links', 'my_add_action_links', 10, 5 );
add_filter( 'plugin_row_meta',     'my_plugin_row_meta', 10, 2 );
 
/**
 * my_add_action_links
 */
 
function my_add_action_links( $actions, $plugin_file ) {
 
 $action_links = array(
 
   'settigns' => array(
      'label' => __('Settings', 'my_domain'),
      'url'   => get_admin_url(null, 'options-general.php?page=my-plugin-options')
    ), 
 
   'faq' => array(
      'label' => __('FAQ', 'my_domain'),
      'url' => 'http://www.my-plugins-site.com/faq'
       )
   );
 
  return plugin_action_links( $actions, $plugin_file, $action_links, 'before');
}
 
/**
 * my_plugin_row_meta
 */
 
function my_plugin_row_meta( $actions, $plugin_file ) {
 
 $action_links = array(
 
   'donate' => array(
      'label' => __('Donate', 'my_domain'),
      'url'   => 'http://www.my-plugins-site.com/donate'
    ));
 
  return plugin_action_links( $actions, $plugin_file, $action_links, 'after');
}
 
/**
 * plugin_action_links
 */
 
function  plugin_action_links ( $actions, $plugin_file,  $action_links = array(), $position = 'after' ) { 
 
  static $plugin;
 
  if( !isset($plugin) ) {
      $plugin = plugin_basename( __FILE__ );
  }
 
  if( $plugin == $plugin_file && !empty( $action_links ) ) {
 
     foreach( $action_links as $key => $value ) {
 
        $link = array( $key => '<a href="' . $value['url'] . '">' . $value['label'] . '</a>' );
 
         if( $position == 'after' ) {
 
            $actions = array_merge( $actions, $link );    
 
         } else {
 
            $actions = array_merge( $link, $actions );
         }
 
 
      }//foreach
 
  }// if
 
  return $actions;
 
}

Feel free to ask anything in the comments of this post.

How to use plugin_action_links and plugin_row_meta filters
Tagged on:

Leave a Reply

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