Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress widgets are disappearing in admin area

My company is being paid to optimize a Wordpress site, I am trying to make some modifications that should be showing up in the widgets section (forms, testimonials etc).

With their custom theme, in the widgets section, on the right hand side where it lists all the sidebars, if I expand any, they are empty. If I drag a text widget over and add "Test", and then Save, it will show up on the front end, but once the widgets page refreshes, if I expand the sidebar again, it shows empty. The widgets show up under inactive widgets but not to the right where I should be able to edit them.

I have tried this using the default theme and the widgets show up as expected. I don't know enough about Wordpress to know where to look to fix the widgets disappearing from the admin sidebar section.

like image 406
jparry Avatar asked May 09 '11 18:05

jparry


People also ask

Why are my widgets not showing up WordPress?

It's likely a plugin or your theme is interfering with normal operation. Isolate the cause by switching to Twenty Twenty-one theme and deactivating all plugins. Widgets added to the back end widget screen should now appear on the site just as widgets added through the customizer would.

Where did my widgets go in WordPress?

You can find your widget area by going to Appearance » Widgets in your WordPress admin dashboard. Here you'll see a list of your available widget areas.

Why doesn't my WordPress have widgets on the Appearance tab?

If your WordPress theme doesn't have any sidebars or widget areas defined, then you will not see the Widgets menu under Appearance.


2 Answers

this is the solution.

we just need to change the id of sidebar. id should be only in small letters. Caps are not allowed. if we use cap id in any of the sidebar, the problem occurs in the same sidebar or any other sidebar of automatically removing widgets on refresh.

I am just mentioning an example below.

This is the Wrong Pattern -

register_sidebar( array(
        'name' => __( 'Main Sidebar', ),
        'id' => 'Sidebar-1',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => "</aside>",
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );

This is the right pattern. Note i just changed the id to correctly configure the widgets saving.

register_sidebar( array(
        'name' => __( 'Main Sidebar', ),
        'id' => 'sidebar-1',
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => "</aside>",
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );

Secondaly, wordpress has not mentioned anywhere, that id should be in small letters, this is another bug by wordpress. But in such big cms, these things are bound to happen.

like image 146
Anirudh Avatar answered Sep 19 '22 10:09

Anirudh


I got the same issue after I changed the sidebars ids (in register_sidebar)

The sidebars show in admin part, I can change their content, which is reflected in front end, but refreshing admin page displays empty sidebars (and saving reflects empty sidebars in front end)

I could solve it by removing the sidebars (remove the calls to register_sidebar), updating admin page, which suddenly showed all the widgets in inactive widgets list (a lot of them since I put new widgets many times before solving the issue), and re-activating the calls to register_sidebar.

like image 37
bonob Avatar answered Sep 18 '22 10:09

bonob