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)
Things I’ve checked for:
- Verify that the ID is not in Caps
- Verify < ?php get_sidebar(); ? > is included in on page.php
- Disabled all plugins
- Switch themes to wordpress default to confirm that widgets are actually working
- Enabled Accessibility mode (doesn’t show up after save)
- 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; ?>
I found that $control_ops[‘id_base’] and first argument of parent::__construct() should be identical.
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.