Time for action - adding the Theme Customizer to our theme

To do this, we need to add some code to our functions.php file.

  1. Open your theme's functions.php file.
  2. Before the closing ?> tag, add the following:
    function add_theme_customizer( $wp_customize )
        {
     
        }
      add_action( 'customize_register', ' add_theme_customizer'),
  3. Save the functions.php file.
  4. To view the Theme Customizer, go to Appearance | Themes, and then in the links below your theme, click on Customize.

What just happened?

We added a new function to add Theme Customizer capability to our theme. Let's have a look at that function:

  • First we define our function, add_theme_customizer. You can give this any name you want, the name we've used makes it easy to see what the function does.
  • The space between the braces is where all the code will go to add specific options to our Theme Customizer.
  • After closing the braces, we add an action. This will run the code inside our add_theme_customizer function when WordPress runs the customize_register function, which is a default function.

Now we can view the Theme Customizer for our theme. As we haven't defined any additional functions, it currently includes the default options provided by WordPress:

What just happened?

We can see the default customizations added by WordPress:

  • Site Title & Tagline: Here we can change the site's name and description
  • Navigation: Change the menu used in the main navigation area
  • Static Front Page: Change the Reading settings if you want the front page to display a static page instead of the latest posts

We can add more options to the Theme Customizer, so let's do it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset