Fatal Error: Twenty_Fourteen_Ephemera_Widget redeclared
-
TwentyFourteen Version 1.4
Fatal error: Cannot redeclare class Twenty_Fourteen_Ephemera_Widget in …/themes/twentyfourteen/inc/widgets.php on line 269
Actually the underlying problem lies in TwentyFourteen’s functions.php code. The registration for Twenty_Fourteen_Ephemera_Widget is done incorrectly in twentyfourteen_widget_init(). I ran across the problem when I was adding widgets to my child theme.
To correct the problem remove the following line from twentyfourteen_widget_init()
register_widget( 'Twenty_Fourteen_Ephemera_Widget' );
and move the require .. widgets.php above the function. Rename the function twentyfourteen_widget_init to twentyfourteen_sidebar_init. Do not forget to rename it in
add_action( 'widgets_init', 'twentyfourteen_widget_init' );
In widgets.php paste the following at the bottom of the file:
function twentyfourteen_widgets_init() { register_widget( 'Twenty_Fourteen_Ephemera_Widget' ); do_action('widgets_init'); } // call widget initialization add_action('init', 'twentyfourteen_widgets_init');
To summarize, the function containing register_sidebar is queued using add_action (‘widgets_init’.
However the function containing register_widget must perform do_action(‘widget_init’) after all widgets have been registered. This function is then queued using add_action (‘init’A quick look at WordPress’ default-widgets.php will show the correct way to initialize widgets.
- The topic ‘Fatal Error: Twenty_Fourteen_Ephemera_Widget redeclared’ is closed to new replies.