Categories: Tips & Tricks

Creating a custom widget

Today let’s learn a simple quick trick on how to create a custom widget. For my example I will show you how I created my Showcase widget located in the middle, to the right of the posts.

First under your functions.php file type in the following:

<?php // Custom Widget
function MyCustomWidget() { ?>
<li class="widget">
    <h2 class="heading">Latest Showcase</h2>
        <ul>
         <?php include(TEMPLATEPATH . '/includes/showcase.php'); ?>
        </ul>
</li>

<?php }

register_sidebar_widget('The Custom Widget for Showcase', 'MyCustomWidget'); ?>
  • Always make sure your code is between the <?php and ?> for it to work.
  • Once we call the function, the rest is assuming html code that you may or may not need.
  • For instance, you may just put in a picture and call it a day. But my code starts with <li< because my sidebar’s start and end with <ul<.
  • Any way, once your done, just set the final “register_sidebar_widget('the widget title', 'the name of the function');

That’s it! Now you have a custom widget with what ever you want!

Web Master

Hi, I am Miguel, I bought this site in 2009. So I now run or manage the site. Please visit my new website or follow me on twitter @W3i.

Recent Posts

WordPress 2.7 Beta 3

WordPress 2.7 Beta 3 has been released for your testing pleasure. Here are some of…

6 hours ago

How to: Add a contact me via Skype™ button

This little trick is really simple and easy. All you need to do is plug…

6 hours ago

Review: WP-DBManager

This powerful plugin is a must-have for WordPress users. With WP-DBManager you can manage your…

18 hours ago

Welcome

Hello, welcome to a new WordPress community site. Join the ever growing and oh so…

1 day ago

Top Membership plugins

Membership plugins/scripts for WordPress paid and free we will review them here today. Ultimate Membership…

2 days ago

The Top 10 Best Free Android Retro Games of all time

Retro games are games that usually refer to 80's and early 90's games that have…

2 days ago