Create widget area header and call in template

To show a widget in your WordPress template you need to do 2 things.

  • Create an area in your WordPress dashboard where you can put your widgets in.
  • Place code where you want to show your widget in your WordPress template.

Create widget area in WordPress dashboard

To create an area you need to place the following code in your functions.php file.

<?php
if ( function_exists('register_sidebar') ){
 register_sidebar(array(
 'name' => 'Widget name',
 'before_widget' => '<div>',
 'after_widget' => '</div>',
 'before_title' => '',
 'after_title' => '',
));}
?>

And for each widget you place this code in functions.php and change the information.

Place code where to show widget in WordPress template

Now you need to place some code where to tell WordPress where to show the widget.

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Widget name') ) : ?><?php endif; ?>

you take the same name as a previously completed in your functions.php.

Advertisements

8 thoughts on “Create widget area header and call in template

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s