报错:Warning: Declaration of description_walker::start_el(&$output, $item, $depth, $args) should be compatible with Walker…

错误详情:

Warning: Declaration of description_walker::start_el(&$output, $item, $depth, $args) should be compatible with Walker_Nav_Menu::start_el(&$output, $data_object, $depth = 0, $args = NULL, $current_object_id = 0) in

你遇到的这个警告,核心原因是自定义导航菜单类 description_walker 重写的 start_el 方法,参数列表和 WordPress 核心父类 Walker_Nav_Menu 不匹配,PHP 抛出兼容警告。

解决办法:

父类 Walker_Nav_Menustart_el 方法标准参数为:

public function start_el(&$output, $data_object, $depth = 0, $args = null, $current_object_id = 0)

而你的子类 description_walkerstart_el 方法参数缺少默认值最后一个参数,且变量名 $item 与父类的 $data_object 不一致,导致兼容警告。

请登录后发表评论

    没有回复内容