WordPress Plugin: Custom Function Widgets

Custom Function Widgets logo Many of the WordPress plugin authors don’t offer widgets, but only raw PHP functions (or hooks) which you have to insert into the theme’s template files. As the number of functions increases it becomes harder to manage it all, especially if you decide to uninstall some of them or add new ones.

It is especially inconvenient for those who are not so savvy, or don’t want to edit theme files. Moreover, if one decides to change the theme, the edits have to be repeated all over again.

Therefore, I made this Custom Function Widget plugin which allows you to create sidebar widgets without ever touching the theme’s files and use these widgets in any theme you like.

This plugin offers you up to 20 widgets you can then add to your theme’s sidebars. All you have to know is:

  1. the name of the function, and
  2. the arguments it requires (if any).

Additionally you can wrap the output in HTML, remove the widget’s title from the output, or remove the default widget wrapper (set in functions.php of your theme).

Download Custom Function Widgets Plugin

Important: It has been tested to be compatible with WordPress 2.5 and 2.6.

Download custom-function-widgets.zip (Version 0.2 / 127 KB) — includes the plugin, readme.txt and four screenshots.

Installation Instructions

  1. Download the plugin and unzip its content
  2. Upload all of the custom_function_widgets directory to /wp-content/plugins/ directory. The final directory tree would like /wp-content/plugins/
    custom_function_widgets/custom_function_widgets.php
  3. Sidebar Widget Arrangement Activate the plugin through the ‘Plugins’ menu in your WordPress dashboard.
  4. Go to ‘Presentation’ > ‘Widgets’ inside your WordPress dashboard. Just bellow the list of sidebars you will see a list of ‘Available Widgets’. There you will find five new widgets ‘Custom Function 1′, ‘Custom Function 2′, etc.
  5. Drag one of these widgets inside the sidebar of your choice. Once it is there, click on the widget’s options button (next to its title), which will open the widget’s options dialog box.
  6. Custom Function Widgets settings There you can specify the following:
    1. Wiget title
    2. Name of the function you want to call (the only obligatory item you must specify)
    3. Arguments to pass to the function, like $onearg = 2, 'Something', $other = 3
    4. HTML to display before the output of the function
    5. HTML to display after the output of the function
    6. Option to hide the title of the widget (which you specified as Widget title) during the ouput
    7. Option to remove the default wrapper of the widget (defined in template.php of your theme’s folder, for each sidebar)
  7. Close the widget options pop-up and click ‘Save Changes’
  8. Now you should see the new widget in the sidebar of you blog/site

Example: creating a widget for Popularity Contest plugin

To better illustrate where to find this information and how to create a widget, lets use the ‘Popularity Contest‘ plugin by Alex King. Once you install Popularity Contest, you have several PHP hooks available:

  • akpc_most_popular($limit = 10, $before = <li>, $after = </li>)
  • akpc_most_popular_in_cat($limit = 5, $before, $after, $cat_ID = current category)
  • akpc_most_popular_in_month($limit, $before, $after, $m = YYYYMM)

To use either of these hooks, simply drag an new ‘Custom Function’ widget (from ‘Available Widgets’ under ‘Presentation’ > ‘Widgets’) inside a sidebar of your choice.

Click on the Widget’s options button and enter the following details (for the akpc_most_popular hook as an example):

  1. Widget title: Most Popular Posts
  2. Function name: akpc_most_popular
  3. Function variables: $limit = 5, $before = <li>, $after = </li>
  4. HTML Before: <ul>
  5. HTML After: </ul>
  6. Leave unchecked both 'Remove Widget title from the output' and 'Remove the default widget wrapper' options

Once you specify a Widget title, it will be also used in your list of widgets (instead of default ‘Custom Function #’).

What’s next?

There are already other WordPress plugins planned for a public release very soon. On this blog you can already see the Tabbed Widgets plugin which enables you to put any number of other widgets inside a single widget as tabs (with an option to rotate). Tabbed Widgets plugin has been released.

Notes

  • I will try to get this plugin submitted at the official WordPress plugin repository, but so far nobody has reviewed my application.
  • Please leave your ideas, suggestions and bug reports in the comments.
 

36 Responses

Suskun

Feb 4 at 22:44

#462

@Kaspars, I got excited when you talked about your plug-in idea. it sounds really good and useful for dummies as you mentioned above.

One of the features making this plug-in important is not only its usage easiness but also the capability of being able to position any non-widget support plugin at theme’s sidebar.

Make sure Tabbed Widgets Plugin is another useful and lifesaving step in wordpress. To me,most of the wordpress users should use tab menu to organize their sidebars. I’ll be waiting for it.

Thank you Kaspars!

Tapac

Feb 10 at 16:05

#509

Good time of day.
Can you help me with this plugin?
I test it on my blog, but nothing seems to appear at sidebar.
Can it be problem of Wordpress version (i use not last release, just 2.3) or maybe something else?

Test on default wordpress theme with 2 additional standart widgets. They seems to appear, but Custom Function Widget is still hidded.

Thanks for plugin, hope that you can help me and make pluggin even better)

Kaspars

Feb 10 at 16:10

#510

Privet, Tapac

Could you please let me know the name of the plugin for which you are using the CFW? I haven’t tested the plugin with other versions than the latest one, but there shouldn’t be any problems, I think.

Also, did you check that particular widget after you inserted it into the sidebar and saved it? It may show you an error message if the name of function is incorrect.

Tapac

Feb 10 at 20:53

#512

Privet-privet

Thanks for fast bug-fix, now it work fine.

Good luck in your development and i’ll wait for tabbed-widgets pluggin

shuron

Feb 19 at 20:22

#569

Maybe you also interested in one plugin that wraps the Popularity contest of Alex King and brings additional “Most Popular” Widget. I call it W-Popularity. It’s full compatible with Popularity contest.

Kaspars

Feb 20 at 3:07

#571

Shuron, does it have any extra features in comparison to the original Popularity Contest plugin or is it just the widget that you have added?

internet

Feb 28 at 14:57

#642

Great plugins for wordpress.. i hope Tabbed Widget add to download page

daya

Mar 6 at 13:10

#718

i have already done something similar to your tabbed browing, it is already released and many wp users are using it

You can see that here spicyexpress.net, I call that plugin as Accordion, But then your upcoming tabb-widget has very good effect, is that moo.tools there.

regards

daya

Kaspars

Mar 6 at 18:55

#720

Hey, Daya. I did check out your plugin before I made both — CFW and the Tabbed Widgets plugins.

I wanted the ability to use other widgets inside the single tabbed widget, while CFW takes care for plugins which don’t offer widget interface. Thus the combination of both offer more flexibility and increased variety of use.

In addition, Tabbed Widgets make use of the original theme styling (defined at function.php) for each widget, and it uses the latest version of jQuery which will be supplied with the upcoming WordPress 2.5.

But your plugin is currently much useful because it is available public while mine is secret and hidden under the hood :)

curt

May 12 at 18:02

#4224

i’d like to use this plugin to force the output of a plugin into columns with CSS. i can’t check from work - locked down terminal - but do you think it’d work with something like a recent comment plugin?

Kaspars

May 12 at 18:35

#4226

Curt, do you mean to apply CSS for the content inside the Admin section? If so, then you’ll have to use a plugin which allows you to append CSS rules to the default WP ones and those set by Baltic Amber themes & schemes plugin (if you are using it).

I don’t know if there any plugins like that, but I made one for my own needs some time ago — called Admin CSS. I have uploaded it for you here: add-admin-css.zip. Unzip, upload, activate and then under ‘Settings’ > ‘Admin CSS’ you can overwrite all admin CSS rules.

Kaspars

May 12 at 18:41

#4227

Sorry, Curt, I thought this comment was on the Baltic Amber plugin’s page :)

For your problem this plugin (custom function widgets) would help only a little bit, as you would have to write a function that splits those comments into two lists that can be placed as columns using CSS yourself.

Mike

May 16 at 19:51

#4437

And now for a REALLY bone-headed question… I don’t have a clue about programming widgets, but I want to take some regular html and get it into a widget. Specifically, I want to take the code generated by the weather.com website and somehow get it into my sidebar. Sorry for the dummy question, but all I’m doing is a blog while I’m in Iraq and I thought it’d be cool to put the current weather up on my WP… The code is literally like 10 lines, so I thought this would be easy (NOT!)
Thanks.

Mike

May 16 at 19:53

#4438

Sorry, I never did ask my question… Might this CFW widget help me do what I’d like to do?

Justin Kent

May 31 at 20:27

#5062

Are you still planning on releasing the tabbed widgets plugin? It looks cool, I’d like to try it.

Kaspars

Jun 1 at 14:01

#5090

Justin, I just sent you an email with the latest version of the tabbed widgets plugin that I am currently using.

I will release it officially (through WordPress Extend) once the documentation is done.

Justin Kent

Jun 1 at 15:18

#5095

Wow! Thanks a lot, very nice of you.

shadowstorm

Jun 5 at 7:19

#5354

Are you still planning on releasing the Tabbed Widgets plugin? From the source and the way you described it looks to be a much cleaner implementation than some of the other options out there (which either break the sidebar entirely or still result in hardcoding). I’d definitely be interested in seeing it/using it/contributing if it was available.

Kaspars

Jun 9 at 12:24

#5581

shadowstorm, I sent you an email with the plugin attached a few days ago. Any feedback or bug reports are always appreciated.

Li-An

Jul 13 at 18:11

#7400

Interesting but the text widgets allowing php code seem to have the same use or am I bad ?

Kaspars

Jul 13 at 18:29

#7402

Li-An, this plugin takes care of situations when the code you would enter in a PHP “text widget” produces an error.

Secondly, having the option to enter raw PHP might be a potential security risk.

I use it for Popularity Contest and a few other plugins and so far I haven’t had the need for raw PHP.

Li-An

Jul 13 at 18:34

#7403

Thank you for your answer. I can understand now the real utilisty of your plugin

Acemi Yazar

Jul 28 at 7:24

#7500

Thanks this widget realy great.

trelas

Jul 31 at 4:14

#7520

How can I use this?
adsensem_ad(’Test’)

don´t work by my

Function name:
adsensem_ad

Function variables:
‘Test’

THX for Help

Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line=""> . If you post HTML or PHP code, don't forget to convert it to HTML entities.


About the Author

Kaspars is a physics student and a graphic designer working on the web since 2000. Read more »

Reverse lookup a 425-533-xxx phone number easily.

Close
Powered by ShareThis