Sep 21, 2011
admin

Add new widget in wordpress

Hi Friends !! I am back in blogging after long time. Are you looking for adding new widget in wordpress ? I had this requirement few days ago and I found a solution for this. I have done some custom code  in wordpress and I got my solution.

Do you want to add different widget for different template page ? Are you finding about how to show dynamic widget in template ?
Then your search end here. I will show you today that how you can add new widget and how you can call it in template.

First find functions.php in your theme folder. If not then create  functions.php. Then add below code in that file :

register_sidebar( array(
'name' => __( 'Test Sidebar', 'twentyeleven' ),
'id' => 'sidebar-6',
'description' => __( 'This is a test sidebar', 'twentyeleven' ),
'before_widget' => '<aside id="%1$s">',
'after_widget' => "</aside>",
'before_title' => '<h3>',
'after_title' => '</h3>',
) );

After adding this in your function.php, in admin, you can see one sidebar block in widget.

Now How to show this particular sidebar in template ? Its also an easy task. Open template file (you can also put this in page.php).

And place below code in at location where you want to show that widget:

<?php if ( is_active_sidebar( 'sidebar-6' ) ) : ?>

<div id="first" class="widget-area" role="complementary">

<?php dynamic_sidebar( 'sidebar-6' ); ?>

</div>

<?php endif; ?>

Thats it !! You can add as many widgets as you want in your site. You can make unique look.

If you have any doubt or any query then comment on this or you can directly contact me via contact form.

Thanks!!

  • rocky

    this is called to add sidebar in wordpress not widget its long process to create widget

Support to grow

If you think my post is helps you then please make donation and do support to grow:

PHP Genious Services

I am a PHP freelancer india, PHP Developer india, PHP programmer india, Wordpress Freelancer india, Wordpress customization services, Wordpress Plugin Developer, Wordpress theme customization, Wordpress plugin customization, Magento Freelancer, Magento Developer india, Magento customization services, Magento theme integration, Opencart Developer india, Zencart Freelancer, Opencart customization, Opencart plugin development, HTML and CSS customization, cakePHP Developer, cakePHP Freelancer india, Ecommerce Developer india

Click Here for

Follow me on Facebook

Categories

Get Adobe Flash player