Working with Theme Widgets

In this section, we'll take a look at widgets.

Right now, we have a sidebar, but this is just static content in our php file. So we want this to come from the widget system. Also, we should be able to add multiple widgets in the sidebar. Now, on the blog page, and on any other page, this is going to be the only widget aside from a custom Home page that we'll create later on. However, we will add those positions in our functions file.

So, let's open up functions.php, and go right under the after_theme_setup action; this will be to set up widget locations. We'll create a function, call it init_widgets() and it will take an id; then, we'll say register_sidebar. Now, even though this is called register_sidebar, this ...

Get Learn to Create WordPress Themes by Building 5 Projects 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.