WordPress Widget Disappears on save

I’ve created a custom theme after viewing some tutorials and I’m having some issues with widgets saving/displaying. Whenever I drag and drop a widget in the admin panel, if i refresh the page and it just disappears and nothing is displayed. I’ve googled for hours and I’m not closer. Hopefully someone here has seen the same issue

This area always shows up as empty once I save and reload from the admin page (none of the widgets are active either)
enter image description here

Read More

Things I’ve checked for:

  1. Verify that the ID is not in Caps
  2. Verify < ?php get_sidebar(); ? > is included in on page.php
  3. Disabled all plugins
  4. Switch themes to wordpress default to confirm that widgets are actually working
  5. Enabled Accessibility mode (doesn’t show up after save)
  6. Verify latest version of Jquery

I’ve included this in my functions.php:

// Register Widget
function ecma_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Main Widget Area', 'ecma' ),
        'id'            => 'custom1',
        'description'   => __( 'Appears in the footer section of the site.', 'ecma' ),
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="blue">',
        'after_title'   => '</h3>',
    ) );

    register_sidebar( array(
        'name'          => __( 'Secondary Widget Area', 'ecma' ),
        'id'            => 'custom2',
        'description'   => __( 'Appears on posts and pages in the sidebar.', 'ecma' ),
        'before_widget' => '<div>',
        'after_widget'  => '</div>',
        'before_title'  => '<h3 class="blue">',
        'after_title'   => '</h3>',
    ) );
}
add_action( 'widgets_init', 'ecma_widgets_init' );

Sidebar.php

<?php
/**
 * The sidebar containing the secondary widget area, displays on posts and pages.
 *
 * If no active widgets in this sidebar, it will be hidden completely.
 *
 */

if ( is_active_sidebar( 'home_right_sidebar' ) ) : ?>
            <div id="sidebar">
                <?php dynamic_sidebar( 'custom1' ); ?>
            </div><!-- .widget-area -->
<?php endif; ?>         

Related posts

Leave a Reply

2 comments

  1. I found that $control_ops[‘id_base’] and first argument of parent::__construct() should be identical.

    class MostRecentWidget extends WP_Widget {
    
        public function __construct() {
            $widget_ops = array(
                'classname' => 'most-recent-widget',
                'description' => 'Displays Most Recent in sidebar'
            );
            $control_ops = array(
                'id_base' => 'most-recent-widget'
            );
            parent::__construct('most-recent-widget', 'Most Recent Widget', $widget_ops, $control_ops);
        }
    }
    
  2. While writing themes from scratch is possible, in my opinion it’s must easier to use starter themes like underscores. That way, much of the basic structure is taken care of, and you can be sure that anything that breaks is additional code you put on top of it, making troubleshooting a lot easier.