Created
November 9, 2017 19:21
-
-
Save Sstobo/bd6b751a6e6f3ad951b52ef973d633c2 to your computer and use it in GitHub Desktop.
[WP sidebar] #wp #sidebar
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
To create a widgetized area in a WordPress theme, in your functions.php file you will need to add: | |
function my_widgets_init() { | |
register_sidebar( array( | |
'name' => esc_html( 'Sidebar' ), | |
'id' => 'sidebar-1', | |
'description' => '', | |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
'after_widget' => '</aside>', | |
'before_title' => '<h2 class="widget-title">', | |
'after_title' => '</h2>', | |
) ); | |
} | |
add_action( 'widgets_init', 'my_widgets_init' ); | |
Now that we've registered our sidebar, we actually need it to show up somewhere in our theme! | |
So in your sidebar.php file: | |
<?php | |
if ( ! is_active_sidebar( 'sidebar-1' ) ) { | |
return; | |
} | |
?> | |
<div id="secondary" class="widget-area" role="complementary"> | |
<?php dynamic_sidebar( 'sidebar-1' ); ?> <------------------actual place it will appear | |
</div><!-- #secondary --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment