WordPress.org

Support

Support » Plugins and Hacks » How I can hook function in class "Walker_Nav_Menu extends Walker"?

How I can hook function in class "Walker_Nav_Menu extends Walker"?

  • I need to modify function start_el of class “Walker_Nav_Menu extends Walker“. add_filter hook added to function.php not working. How I can resolve it. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Not sure if you’re still looking for the answer to this or not… However, walkers are a little bit different than filters or actions. You would need something like this in your functions.php:

    class Your_Class_Name extends Walker_Nav_Menu {
    
    function start_el(&$output, $item, $depth, $args) {
       /* Your custom code goes here.
        * I encourage you to copy the existing Walker_Nav_Menu
        * and then just make your changes.
        */
       }
    }

    Then, when you call a menu in your template files, make sure to include 'walker' => new Your_Class_Name() in your array that specifies the arguments for wp_nav_menu().

    Hope that helps….

    Many thanks JPry !
    I don’t know about viter-z-bayraku, but your comment made me save a good amount of time 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How I can hook function in class "Walker_Nav_Menu extends Walker"?’ is closed to new replies.