Simple Method to Create Custom WordPress Widget in Admin Dashboard

Wordpress Custom Widget

WordPress widgets are easiest way to add our custom information to our website. Let we see how to create custom wordpress widget, before moving, kindly check, how to create wordpress plugin.

To create custom wordpress widget in admin dashboard, we have to follow few structures.

 //1.  widgets_init action hook to be called first with custom function name

  // 2. Register our new widget

 3. Extend the class with WP_Widget, the extends class should have,

  • The constructor [Function name should be the same as class name]
  • function form($instance) [Function to designing widgets with HTML code]
  • function update($new_instance, $old_instance) [Function to update the information]
  • function widget($args, $instance) [Function to tell how to display in the webpages]

 Explaining in detail, We are going to design the widget with three fields, getting input from admin dashboard and displaying in website.

  • Name [text field]
  • Domain [text field]
  • Designation [text field]

Complete coding to create widget

custom wordpress widget

 Conclusion

 

Designing custom wordpress plugin and making widget for that plugin is easy with the above functions and structures.

VINOTH

Love to code with PHP, MySQL, HTML, AJAX, CSS, JQuery and JavaScript. My Slogan : Share.. Share.. Share.. What ever knowledge or skill you have..

Leave a Reply

26 Responses to “Simple Method to Create Custom WordPress Widget in Admin Dashboard”

  1. manav September 30, 2013 at 7:19 am // Reply //

    Nice and very useful blog………

  2. kuldip October 24, 2013 at 12:14 pm // Reply //

    nice blog . it is useful for me

  3. Md. Elias November 12, 2013 at 12:37 pm // Reply //

    This is so nice and a helpful article ever. would you pls get me a video and image up loader widget . it will be very helpful for me….
    Looking forward…
    Regards,
    md. Elias

  4. Arshad November 17, 2013 at 2:37 pm // Reply //

    That tutorial was great! But I want some extra things i.e
    I want a drop down in the widget form for categories, and show the latest 5 Post names in of the selected category.
    I used the wp_dropdown_categories( $args ); to show the categories in drop down but I can not figure out how to get the $instance[] value for selected category.

  5. Display Post Titles from Category Selection Wordpress November 18, 2013 at 3:11 pm // Reply //

    […] to read the article. This plugin will help you to display post title based on category selection in admin dashboard widget […]

  6. topkaos November 24, 2013 at 9:56 am // Reply //

    Thank You for the tut

  7. Author List Wordpress Plugin December 24, 2013 at 5:24 am // Reply //

    […] To show the Author list through  wordpress widget. […]

  8. H January 1, 2014 at 4:30 pm // Reply //

    HI,

    I see you are putting the class inside t he functions.php file. Wouldn’t be recommended to have classes outside this file and call them in?
    Can you tell me why you are using this approach?
    Thanks!

    • vinoth January 1, 2014 at 4:49 pm // Reply //

      Hi.. am not using the class inside the function.php.. that code will be placed inside the plugin file.. if u want to know more. Please check our plugins like category widget, tag widget etc..


      If you like my plugin or service - Please Donate Me

  9. Friends Link Widget Wordpress Plugin January 2, 2014 at 6:40 pm // Reply //

    […] link widget’ plugin gives Simple method to add our friends website url to our website through widget. We can able to add upto five friends website details and also able to make the link open in new […]

  10. Random Banner Wordpress Plugin January 24, 2014 at 10:10 am // Reply //

    […] title can be added for that banner in widget […]

  11. Fast Loading WordPress Theme - Buffercode-Blue February 23, 2014 at 10:44 pm // Reply //

    […] Totally five widgets that is Right sidebar, Social Network, Left Footer, Center Footer, Right Footer. Through this widgets user have flexible to add their desired plugin widgets. […]

  12. Native June 13, 2014 at 3:18 am // Reply //

    Thank You for this snippet. I have a question. How do I stop the empty tags from printing into the html if the field is empty? I tried to wrap the elements with if statements, but they still are displaying empty on the front end.

    if ($domain != ”) {
    echo ‘Domain: ‘ . $domain . ”;
    }

    I’m not very savvy with PHP, but would appreciate any help on adding conditional statements to stop the empty fields from showing up on the front end.

    Thank You again for this article!

  13. Juskteez June 17, 2014 at 9:21 am // Reply //

    Thank you! It’s work :D

  14. Dhaval Parekh July 10, 2014 at 7:19 pm // Reply //

    Thanks vinoth…
    it is very useful .. :)