jcs/menu_item_args

jcs/menu_item_args filter is used to edit wp_nav_menu options on a per menu item basis allowing a truely customizeable menu output.

Example – Display Menu Item Image

This example shows how to add an image before a menu item depending on that items object type.

add_filter( 'jcs/menu_item_args', 'jcs_menu_item_args', 10, 2);
function jcs_menu_item_args($args, $item){
 
    switch($item->object){
        case 'page':
            // add blue 10 pixel image before the menu item name
            $args->link_before = '<img alt="" src="http://placehold.it/10x10/0000FF" />';
        break;
        case 'term':
            // add green 10 pixel image before the menu item name
            $args->link_before = '<img alt="" src="http://placehold.it/10x10/00FF00" />';
        break;
        case 'post':
            // add red 10 pixel image before the menu item name
            $args->link_before = '<img alt="" src="http://placehold.it/10x10/FF0000" />';
        break;
    }
    return $args;
}