Chapter 21. Managing Widgets

Up to now, you've worked with content that appears in the main body of your website, but WordPress makes it easy to control the content in the sidebar, without having to know HTML or other coding. That's the purpose of what are called widgets. In this lesson, I show you how they work and how they can work for you.

What Are Widgets?

In a WordPress theme, the sidebar area of the site is controlled through coding in the template files. Lists of pages, categories, links, and other information appearing in the sidebar is controlled by scripting written by the theme builder. This is what's called hard-coding.

However, WordPress offers an alternative to theme builders. They can add another piece of code that allows users to control the structure of the sidebar through widgets. Widgets are individual pieces of code that can be customized and moved around with no knowledge of code. For example, if you want to display a list of categories, there's a widget that will do that, while allowing you to decide whether it appears as a list or a dropdown menu simply by checking a box. What's more, you can easily move this widget so that the categories appear near the top of the sidebar instead of near the bottom.

When a theme is widget-enabled, the first time a user activates a widget, the existing sidebar code is ignored and visitors will only see what widgets are activated. If all widgets are removed, the original theme code kicks in again.

Though widgets are most commonly ...

Get WordPress® 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.