Try this:
in your header replace your code by this:
<?php if ( is_active_sidebar( 'sidebar-my-widget' ) ) : ?>
<?php dynamic_sidebar( 'sidebar-my-widget' ); ?>
<?php endif; ?>
and in your function replace your code by this:
add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
register_sidebar( array(
'name' => __( 'My Widget', 'theme-slug' ),
'id' => 'sidebar-my-widget',
'before_widget' => '<div class = "My Widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
}
good luck!
-
This reply was modified 7 years, 1 month ago by bcworkz. Reason: code fixed, otherwise syntax errors occur