Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to make 2-line navi, and found this code.

add_filter('walker_nav_menu_start_el', 'description_in_nav_el', 10, 4);

function description_in_nav_el($item_output, $item, $depth, $args)
{
    return preg_replace('/(<a.*?>[^<]*?)</', '$1' . "<span>{$item->post_content}</span><", $item_output);
}

http://pastebin.com/Fw3e0wqC

Where come from these arguments $item_output and $item? I know $item_output is nav_menu html source and $item is nav_menu, but I don't know in which function the html are generated.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You should look on ow WordPress Plugin Api works.

When you add a filter, the function that hook into that filter receive the argument from the function: apply_filters.

This function pass at least one argument, but can pass more, and always aspect a value returned.

So if you can write

add_filter( 'walker_nav_menu_start_el', 'description_in_nav_el', 10, 4 );

is because somewhere in the code there is a line that appear something like:

$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );

So the argument you can use, are passed to your function via apply_filters and they are generated in the function that contain that line.

when you want to know more on a hook, first play where to see, is Codex, however not all hooks can be founded there, in that case best place where look is code.

I think you use a software to write your code, and most probably that software have a search feature among all files in a folder1, so once you know what to search:

apply_filters( 'walker_nav_menu_start_el'

try yourself, you'll find the file /wp-includes/nav-menu-template.php at line 169 contain just the line I posted above, inside the method start_el of the class Walker_Nav_Menu.

1 If you are familiar and use any Unix SO, of course you'll have easier life using grep, but in that case, you already know it...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.