TheWebs TheWebs - 9 months ago 33
PHP Question

WordPress Sidebar widgets not staying

WordPress 3.5

I build a dynamic sidebar via WordPress register_sidebar documentation to which looks like:

$sidebar = array(
'name' => 'Main Side Bar',
'id' => 'Aisis_Side_Bar',
'before_widget' => '<li>',
'after_widget' => '</li>',
'before_title' => '<h2>',
'after_title' => '</h2>'


The problem is, when I go into the widgets section of the admin section to drag and drop widgets onto the sidebar, everything works. If I refresh or leave that page and come back the widgets are gone and the sidebar is empty.

They also do not show up on the front end.


Answer Source

Posting here because it is too long for a comment, not really an answer.

And then you have something like <?php dynamic_sidebar('Main Side Bar'); ?> in your template?

There are two times I've seen WordPress widgets disappear, and both are related to the page doing everything via Ajax. The first is when you are only viewing the Appearance >> Widgets and you leave the page open for a long time, WordPress signs you out but the page keeps acting like normal, even though nothing is saving.

The other time is when there are multiple admins. All widgets and their options get saved every time you click save on any widget, it doesn't just save the info for the widget you clicked save on. So if another person is logged in as admin and is viewing Appearance >> Widgets, then you save your widget to "Main Side Bar", it won't show up in their screen unless they refresh Appearance >> Widgets. So now if they click save on any widget, it saves "Main Side Bar" as empty and "erases" your widget.

Also, if you create multiple widget areas, be sure to add them below the other ones in functions.php. WordPress puts widgets in the proper area based on its ID number, not based on its name or the ID you set. So if "ABC" is the first widget area you register, then you drop some widgets in, then you go register a new area "DEF" above the other one in functions.php, ABC will now be empty.

If none of those situations apply to you, you might want to try changing the ID to use hyphens just for the heck of it. Then start looking in your error log, disabling all plugins, making sure mod_security isn't intercepting the post, stuff like that.