Javier Kezern
asked 4 years ago

I’m trying to override start_el function in mega-menu.php file in a child theme of dwfocus.
I have created the same file in dwfocus-child/inc/mega-menu.php and included it in dwfocus-child/functions.php.
Now I’m getting this error.
Fatal error: Cannot redeclare class DW_Mega_Walker in F:xampphtdocswordpresswp-contentthemesdw-focusincmega-menu.php on line 120

1 Answers
Allen
answered 4 years ago

I think the main Problem here is that you didn’t check the class is using or not, so the class will be re-declare again when you try to override it.

first, you can open the mega-menu.php in parent theme and wrap the class like this:

if( !class_exists( 'DW_Mega_Walker ' )) {
      class DW_Mega_Walker ....
}

And then you can override the class in child theme.
Hope this help !

Powered by DW Question & Answer Pro