How To Add Custom Widget Area And Theme Customizer API On Your WordPress Theme

by Ahsan Parwez  July 2, 2014

In my previous two posts, I taught how to convert an HTML theme into a WordPress one and how to build and integrate a fully functional blog into your newly-converted WordPress theme.

WordPress Business Theme From An HTML One

In this final part, we are going to add a few more functionalities in WordPress (WP) backend to make our theme more feature-rich.

We will learn:

  • How to add custom widget areas in WordPress backend and frontend
  • How to use the “Theme Customizer” to change logo of theme

Adding Custom Widget Areas

Widgets areas allow us to add custom text, links, navigation menus, social links, calendar and so much more. It would be great if we edit following areas as widgets.

Theme Areas

Till now ,we will not be able to see “Widgets” option under the Appearance->Widget in WP Admin for our WordPress theme.

To use widgets, we first need to enable them.

Add the following code in functions.php to enable Widget in WordPress admin.

Widget area activated

The above code will register a new widget called “Homeleft Widgets”. To use this widget, we need to insert following code in the area we want.

In our case, we will place it in index.php in place of “Careful Analysis” removing its html.

Code replaced

Now, whatever widget we place in “Homeleft Widgets”, it will display on the homepage.

We can insert as many widget areas to our theme as we want. First, we will register a widget and then call it in the area we want.

Using Theme Customizer To Change Logo

We can use the Theme Customization API to enable the Theme Customize options in the WP Admin. The Theme Customizer gives us an instant live preview of the changes we make in a website.

First, we will need to enable the option by adding following code to our functions.php:

Now, we will define what sections, settings, and control we want by adding the following code.

The above code will enable the “Customize” option in the WP admin themes.

Theme Customizer activated

Next, we are going to add the following code in header.php replacing the HTML logo.

The above code will call the themeslug_logo if it is uploaded through the Theme Customizer. Otherwise, it will display the title and description of the website.

We will wrap it up here. You can play with the techniques and functions taught in this tutorial series to give your theme a much finer look. You can add widget areas in the footer.php, create sidebar in the blog section, and add widget areas there too. There is so much we can do with the simple techniques we covered here. Do let me know what would you like to read next.

Start Creating Web Apps on Managed Cloud Servers Now!

Easy Web App Deployment for Agencies, Developers and E-Commerce Industry

About Ahsan Parwez

Ahsan is the Community Team Manager at Cloudways – A Managed Cloud Hosting Platform. He loves to solve problems and help Cloudways’ clients in any aspect he can. In his free time, you can find him playing RTS PC games.

Stay Connected:

You Might Also Like...

  • indrajeet

    how to make responsive if i convert html file to wordpress theme what code are written in this

  • indrajeet

    sir my theme in not working responsive when i install all this plugin this plugin its not working. please help me !!!

  • indrajeet

    sir also need slider code when i convert html theme in wordpress theme…what code are written in this
    thank you!