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

WordCamp Las Vegas: The WordPress codex

I am at the WordCamp convention in Las Vegas and

5 hours ago

6 Best Online Plagiarism Checkers to Detect Duplicated Content

This post discusses the importance of detecting and removing plagiarized content for credibility, originality, avoiding…

17 hours ago

Disable caching of your site or post

I talked about Disabling search engine on search pages in a previous post using the…

1 day ago

WordCamp Las Vegas Near

The time is near, only 6 hours and some change to to get your tickets…

2 days ago

Disable search engine on search pages

A good idea when trying to get the most out of your blog is usging…

2 days ago