I recently moved my wp site from localhost to the web and lost all my widgets.

When I browse to Appeareance > Widgets in the wp dashboard I see the default widgets but not my custom widgets.

My widgets are declared in separate php files under mytheme/widgets. They are registered with the following code:

in myWidget.php:

add_action( 'widgets_init', function() { register_widget( 'myWidget' ); } );

in theme/functions.php:

$widgets = glob(get_template_directory().'/widgets/*.{php}', GLOB_BRACE);
foreach ($widgets as $widget) {
    $className =  str_replace('.php', '', basename($widget) );
    include $widget;

I am new to web development and am having a hard time to identify and fix the issue. Any help will be much appreciated.


  • Does it work locally, but not on live site? Commented Sep 27, 2016 at 15:42
  • Yes it works fine on localhost.
    – krollynn
    Commented Sep 27, 2016 at 15:44
  • Maybe the glob function is not working on your host? have you tried to dump $widgets in your code to see what it returns? Commented Sep 27, 2016 at 15:45
  • I tried that just now. It turns out that GLOB_BRACE was not recognized. I removed it and the widgets are back. My problem seems simple and silly now but thank you so much for your help ^^
    – krollynn
    Commented Sep 27, 2016 at 15:53
  • Remember to put that as an answer and accept it :) you're welcome. Commented Sep 27, 2016 at 16:34

1 Answer 1


The glob function is not supporting GLOB_BRACE on the host. The code in functions.php can be replaced by

$widgets = glob(get_template_directory().'/widgets/*.php');
foreach ($widgets as $widget) {
    $className =  str_replace('.php', '', basename($widget) );
    include $widget;

to fix the issue.

Your Answer

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

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