Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is WordPress Widget & How To Create Your Own Widgets In WordPress

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 357
    Comment on it

    A wordpress widget is a small component of an interface, that enables a user to perform various action. You can add, arrange, and remove widget from the sidebar of your blog. Widgets make it easy to customize the content of your sidebar of your blog.


    **How to create wordpress widget**

    to create a new widget in your wordpress CMS blog, you only need to extend the standard WP_Widget class and some of its functions.

    Example:

    1. class My_Widget extends WP_Widget {
    2.  
    3. /**
    4. * Sets up the widgets name etc
    5. */
    6. public function __construct() {
    7. // widget actual processes
    8. }
    9.  
    10. /**
    11. * Outputs the content of the widget
    12. *
    13. * @param array $args
    14. * @param array $instance
    15. */
    16. public function widget( $args, $instance ) {
    17. // outputs the content of the widget
    18. }
    19.  
    20. /**
    21. * Outputs the options form on admin
    22. *
    23. * @param array $instance The widget options
    24. */
    25. public function form( $instance ) {
    26. // outputs the options form on admin
    27. }
    28.  
    29. /**
    30. * Processing widget options on save
    31. *
    32. * @param array $new_instance The new options
    33. * @param array $old_instance The previous options
    34. */
    35. public function update( $new_instance, $old_instance ) {
    36. // processes widget options to be saved
    37. }
    38. }
    39.  
    40. // Register My_Widget widget
    41. function register_my_widget() {
    42. register_widget( 'My_Widget' );
    43. }
    44. add_action( 'widgets_init', 'register_my_widget' );

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: