17

I'm currently working on a WordPress site and whenever in the admin I go the Appearance > Menus page I get the following error:

ErrorException: Runtime Notice: Declaration of Walker_Nav_Menu_Edit::start_lvl() should be compatible with that of Walker_Nav_Menu::start_lvl() in wp-admin/includes/nav-menu.php line 203

It seems like some sort of PHP compatibility issue. I'm running PHP 5.3.10 on my local dev machine.

What would be the best way to remedy this problem?

3 Answers 3

30

From class Walker_Nav_Menu:

function start_lvl( &$output, $depth = 0, $args = array() )

Your child class must use the same signature: three arguments, the first one passed by reference. Every difference will raise the error you got.

Note that $args defaults to an empty array, but you get an instance of stdClass, not an array. This is WordPress.

3
  • I know. It's a WordPress class, it's not for me to change. My question is what's the best way to work around the problem (preferably without meddling with WP's internals)...
    – Luke
    Apr 9, 2013 at 4:41
  • 4
    You are not being told to meddle with WordPress core. You need to alter the way you define your method in your extended class to match the way WordPress does it in the original class.
    – s_ha_dum
    Apr 9, 2013 at 13:17
  • 1
    Got it. The error was throwing me off. It gave me the impression the problem was in WP core but it's referring to the definition of the signature, not where the problem occurred.
    – Luke
    Apr 9, 2013 at 23:04
16

From class Walker_Nav_Menu replace this lines

function start_el(&$output, $category, $depth, $args) {

to

function start_el(&$output, $category, $depth = 0, $args = array(), $current_object_id = 0) {

function end_lvl(&$output, $depth, $args) {

to

function end_lvl(&$output, $depth = 0, $args = array()) {

function start_lvl(&$output, $depth, $args) {

to

function start_lvl(&$output, $depth = 0, $args = array()) {

function end_el(&$output, $category, $depth, $args) {

to

function end_el(&$output, $category, $depth = 0, $args = array()) {
5
  • Can you also explain how it works instead of just adding the code and how is it different from the accepted answer
    – bravokeyl
    Sep 23, 2017 at 10:45
  • Yes; The answer is updated in 2015, and it does not work on the new version of Wordpress link Sep 23, 2017 at 13:54
  • Yes, so explanation of the answer would be awesome.
    – bravokeyl
    Sep 23, 2017 at 17:18
  • 1
    This saved my ass, definitely the correct answer if you have 4 error messages, for function start_el, function end_el, function start_lvl, function end_lvl
    – Stephen
    Jun 8, 2018 at 16:29
  • Where or how we go to the class Walker_Nav_Menu??? I do not know how or where It is selected!!!!!
    – riemannium
    Nov 13, 2019 at 22:14
0

This was the same in my case. You get old nav menu walker codes, and it says what you should do when you turn on wp_debug(true)

Menu_Frontend::start_lvl(&$output, $depth) should be compatible with Walker_Nav_Menu::start_lvl(&$output, $depth = 0, $args = NULL) in C:\xampp\htdocs\shopnet\wp-content\themes\Viteeo\hades_framework\helper\megamenu.php on line 314

As you can see you need to change some code line what PHP refers to you. In above error notice you should replace start_lvl(&$output, $depth) with start_lvl(&$output, $depth = 0, $args = NULL) so other processes are the same. But don't forget to write function opening tag { at the end, like this NULL) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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