Skip to content

Instantly share code, notes, and snippets.

@Tsunamijaan
Created January 5, 2019 09:54
Show Gist options
  • Save Tsunamijaan/b7683bbf8f29499db954e7b13def6027 to your computer and use it in GitHub Desktop.
Save Tsunamijaan/b7683bbf8f29499db954e7b13def6027 to your computer and use it in GitHub Desktop.
Register widget in wordpress
function my_custom_theme_widgets() {
register_sidebar( array(
'name' => 'My Widget',
'id' => 'widget_id',
'before_widget' => '<div class="widget_div">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
add_action('widgets_init', 'my_custom_theme_widgets');
You can call widget via below:
Single widget:
<?php dynamic_sidebar('widget_id'); ?>
Conditional widget:
<?php if ( ! dynamic_sidebar( 'sidebar-top' ) ) : ?>
// Your conditional codes
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment