Posted By

jschultz76 on 09/29/10


Tagged


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

laurentzziu
shalomfriss
booski
adambundy
fyreflyX


Custom Widget in WordPress


 / Published in: PHP
 

The code below is used to create a custom widget area in a WP template

  1. <?php
  2.  
  3. /* the following goes into the functions.php file */
  4. if (function_exists('register_sidebar')) {
  5.  
  6. register_sidebar(array(
  7. 'name' => 'My Custom Widget',
  8. 'id' => 'my_custom_widget',
  9. 'description' => 'Widget area for home page center left column',
  10. 'before_widget' => '<div id="widget-id" class="widget %2$s">',
  11. 'after_widget' => '</div>',
  12. 'before_title' => '<h2>',
  13. 'after_title' => '</h2>'
  14. ));
  15.  
  16. }
  17.  
  18. ?>
  19.  
  20. <?php
  21.  
  22. /* this goes into your template file where you want the widget to appear */
  23.  
  24. ?>
  25.  
  26. <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('my_custom_widget')) : else : ?>
  27. <div class="widget">
  28. <h2>Widget Ready</h2>
  29. <p>This my_custom_widget is widget ready! Add one in the admin panel.</p>
  30. </div>
  31. <?php endif; ?>

Report this snippet  

You need to login to post a comment.