Created
January 5, 2019 09:54
-
-
Save Tsunamijaan/b7683bbf8f29499db954e7b13def6027 to your computer and use it in GitHub Desktop.
Register widget in wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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