How to use plugin_action_links and plugin_row_meta filters

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.

Add Walker_Nav_Menu extension with Genesis

1
2
3
4
5
6
7
8
9
10
11
12
// filer wp_nav_menu_args to add the custom walker to wp_nav_menu(), used by genesis_do_nav()
add_filter( 'wp_nav_menu_args', 'my_navigation_walker' );
 
function my_navigation_walker ( $args ){
    if( isset( $args['menu_class'] ) && 'menu genesis-nav-menu menu-primary' === $args['menu_class'] ) {
	if( class_exists( 'My_Navigation' ) ) {
		$args['walker'] = new My_Navigation(); 
	}
    }
 
    return $args;
 }

Source found here

Example to fix navigation on scroll

This is an example to fix the navigation to the top of the page when scrolling down. This case scenario is a header (site-header) and a navigation under it (nav-primary).
It takes in consideration if the user is logged in to calculate the WordPress adminbar height.

functions.php

1
2
3
4
5
6
7
8
9
add_action( 'wp_enqueue_scripts', 'load_my_scripts' );
function load_my_scripts() {
 
     wp_enqueue_script( 'my-script', get_bloginfo( 'stylesheet_directory' ) . '/assets/js/my-scrip.js', array( 'jquery') );
 
     wp_localize_script( 'my-script', 'my_vars', array(
			'logged_in' => is_user_logged_in() ? 'yes' : 'no',
     ));
}

my-script.js

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
jQuery(function( $ ){
 
	var navigation = $('.nav-primary');	
	var header     = $('.site-header');
 
	var navigation_height = parseInt( navigation.css('height') );
	var header_height     = parseInt( header.css('height') );
	var adminbar_height   = 0;
 
	if( my_vars.logged_in == 'yes' ){
		adminbar_height = 	parseInt($('#wpadminbar').css('height'));
	}
 
	$(window).scroll( function(){
 
	    var scrollTop              = $(this).scrollTop();
	    var topDistance_navigation = navigation.offset().top;
       	    var topDistance_header     = header.offset().top;
 
	    // if navigation hits the top stay fixed
	    if ( topDistance_navigation - adminbar_height < scrollTop ) {
 
                 if( ! navigation.hasClass('nav-fixed') ) {
 
            	     navigation.addClass('nav-fixed');
		     navigation.css('top', adminbar_height);
 
            	}
 
            } 
 
            // if header hits the top remove fixed class
           	if( header_height - adminbar_height  > scrollTop ) {
            	navigation.removeClass('nav-fixed');
            }
        });
 
});

style.css

1
2
3
4
5
6
.nav-primary.nav-fixed{
   position:fixed;
   left:0px; 
   width:100%;
   z-index: 500;
}

Add submenu item to admin menu

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
/*
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function);
example for tools menu
*/
add_action('admin_menu', 'add_submenu_item');
 
function add_submenu_item(){
     add_submenu_page( 'tools.php', 'My Tool', 'My Tool', 'manage_options', 'my-tool', 'display_page');
     // or
     // add_management_page( 'My Tool', 'My Tool', 'manage_options', 'my-tool', 'display_page' );
} 
 
/**
- Settings: options-general.php or use add_options_page()
- Dashboard: index.php or use add_dashboard_page()
- Posts: edit.php or use add_posts_page()
- Pages: edit.php?post_type=page or use add_pages_page()
- Custom post type: edit.php?post_type=custom_post_type
- Media: upload.php  or use add_media_page()
- Comments: edit-comments.php or use add_comments_page()
- Appearance: themes.php or use add_theme_page()
- Plugins: plugins.php or use add_plugins_page()
- Users: users.php or use add_users_page()
- Tools: tools.php or use add_management_page()
*/

Duplicate Menu, time saver plugin

This is one of those simple but very useful plugins. It’s  a time saver.

With this plugin, as you have guessed already by it’s name,  you can duplicate a menu to add it anywhere else on your website.

So imagine you have a really huge (or not as huge) menu on your top navigation and you would like to add the same navigation to your footer. You will be able to do that in a few clicks  with this plugin, otherwise you would have to manually create the menu, add the pages (or whatever you want to add) one by one. So this plugin will save you a ton of time.

Check it out on the wordpress.org repository  http://wordpress.org/plugins/duplicate-menu/

After installing it just go to Appearance -> Duplicate menu.

duplicate-menu-1

Duplicate your menu, and then go to Appearance -> Menus, and you will see your new menu in the list.

duplicate-menu-2

Add a settings link to plugins overview page

1
2
3
4
5
6
7
8
9
function my_add_action_links( $links ) {
 
    $url = get_admin_url(null, 'options-general.php?page=plugin_name');
 
    $links[] = '<a href="'. $url .'">Settings</a>';
    return $links;
}
 
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'my_add_action_links' );