Skip to Content
WordPress® All-in-One For Dummies®
book

WordPress® All-in-One For Dummies®

by Lisa Sabin-Wilson, Cory Miller, Kevin Palmer, Andrea Rennick, Michael Torbert
April 2011
Beginner to intermediate content levelBeginner to intermediate
908 pages
22h 37m
English
For Dummies
Content preview from WordPress® All-in-One For Dummies®

Adding Widgets

Widgets are individual features you can add to theme sidebars. Widgets can add a simple site search, display a calendar, list the most recent posts, and show RSS feed updates. These features just scratch the surface of what widgets offer and what widgets are capable of.

WordPress 2.8 introduced a new widget API that makes widget creation very easy. If you tried creating widgets in the past and gave up because of the difficulty of making them work properly, it's time to try widget creation again.

Coding a simple widget

The format for setting up filters and shortcodes are very similar. Add a function that performs a specific task and then use either add_filter or add_shortcode to register the function as a filter or shortcode.

Widgets are a bit different. Instead of creating one function and registering it, widgets are a collection of functions packaged in a container called a class. The class is registered as a widget using the register_widget function.

Like shortcodes, multiple plugins can be housed in a single plugin file. However, because the code for some of these widgets gets lengthy, each widget will be its own plugin.

The widget plugin we define in the following steps creates a widget that you can use on the Widgets page of your Dashboard (AppearanceimageWidgets) to show a widget in your sidebar that displays “You are logged in as Name” or “Welcome Guest” depending ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

WordPress® 24-Hour Trainer

WordPress® 24-Hour Trainer

George Plumley
Gaming Hacks

Gaming Hacks

Simon Carless

Publisher Resources

ISBN: 9780470877012Purchase book