WordPress Widgets and Sidebars
In WordPress widgets are blocks of content that admin users can add to their site’s widget areas also known as sidebars. WordPress widgets were created to provide an easy way for WordPress admin users to control the design and content of their site without having to code. Most WordPress themes support widgets.
In WordPress a sidebar, widget area or widget-ready area is any region of the page that can contain widgets. The Sidebars theme feature allow admin users of a WP site to assign widgets to widget areas defined by a theme.
There is no default widget area in WordPress. How many widget areas exist and where they’re located is defined by the theme. Most WordPress themes offer at least one widget area for a site’s “left sidebar”.
WP widget areas can also hold admin-created navigation menus (although menu locations cannot hold widgets).
Use Widgets and Sidebars in a Theme
To use widgets and sidebars in a theme:
- Register the Sidebars Theme Feature in the
- Register each widget area using
- Display each widget area using
dynamic_sidebar()in template files.
Enable Theme Support for Sidebars
Register a Widget Area
Display a Widget Area
The get_sidebar() function includes a template file named
sidebar.php if it exists from the themes template directory. This function is the equivalent of
get_footer(), but for
If you do not have a sidebar.php file then get_sidebar() will output a default set of widgets. This is purely for backwards compatibility purposes, as it used to be how sidebars worked. This behavior is now deprecated and you should properly define your sidebars in your theme.