I am using a custom install.php in /wp-content/ to over-ride some defaults when creating sites in a multi-site install. For the most part, this is easy and working really well. I am having difficulty with the widgets though. All I want for widgets is the Search widget and a custom Meta widget we use in-house.

Within my wp_install_defaults() function, I have the following ...

function wp_install_defaults( $user_id ) {
    global $wpdb, $wp_rewrite, $table_prefix;
    lots of stuff setting up default settings and default content

    // Set up default widgets for default theme.
    update_option( 'widget_search', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) );
    update_option( 'widget_vvnumetawidget', array ( 2 => array ( 'title' => '' ), '_multiwidget' => 1 ) );

    update_option( 'sidebars_widgets', array ( 'wp_active_widgets' => array (), 'sidebar-1' => array ( 0 => 'search-2', 1 => 'vvnumetawidget-2' ), 'sidebar-2' => array (), 'sidebar-3' => array (), 'array_version' => 3 ) );

    a few more options are set

This is mostly working, however... initially, only the Search Widget is displaying in the sidebar. If I go to the Widgets admin screen, the custom Meta widget is there where it should be and appears active. If I click on the Save button for it, it then displays properly inn the public sidebar.

I have tried running another update_option for my widget after having updated the sidebar_widgets option.

    update_option( 'widget_vvnumetawidget', array ( 2 => array ( 'title' => 'Second update' ), '_multiwidget' => 1 ) );

That does work in that the title gets updated, but it still doesn't get it to display publicly, until I manually go to the admin screen and click on Save. I do not have to do that for the Search widget.

Any ideas what I am missing?

After looking in the database options table, I see a couple things that make me wonder if it isn't because my custom widget is a plugin? For instance, after install I see the following options...







At this point, to the public face, I have only the Search widget in my sidebar. If I go to the admin, the Search and my custom Meta widget are in the active area for my sidebar (even though my custom one is not displaying). If I click 'Save' for my custom Meta widget, it now displays publicly and if I check what is in the options table, it is now...



So, it's now looking to me like I need too set these defaults for my custom widget, in my install.php file also, OR in my custom widget's php, test for the existence of these defaults, and set the appropriate behaviour there, as it is now treating the absence of defaults as 0 instead of null.

I'll test and report back.

  • Your sidebar_widgets array looks wrong. Jan 15, 2016 at 7:34
  • Thanks @NathanPowell I don't think it's quite that simple, but you've got me looking in the right direction. I looked at that array a little closer, and the part 'wp_active_widgets' => array () should be 'wp_inactive_widgets' => array () but that doesn't really solve things. I think the issue is more to do with my custom widget being a plugin. When I look in the database, I see a few things.
    – verdonv
    Jan 15, 2016 at 14:26

1 Answer 1


So, the actual problem was that I wasn't setting any defaults my custom widget needed to display any content. The widget actually was there, but as I had emptied the title and set no other defaults, it was rendering nothing. My fix for this was two-fold.

1) set at least one default in my install.php file

update_option( 'widget_vvnumetawidget', array ( 2 => array ( 'title' => 'Meta Links', 'register' => 1, 'login' => 1  ), '_multiwidget' => 1 ) );

2) put some logic in my custom widget to display a message if it is installed, but no configuration is set.

Thanks @Nathan for getting me to look a little closer at those settings arrays.

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.