About Components

Watch a demo with Cameron Jones from WP Theme Components and Nathan Wrigley from WP Builds

What is a theme component?

Theme components are bite sized code snippets that can be reused across multiple themes. Using theme components makes it easier to reuse the same code across multiple themes.

What is the difference between theme components and plugins?

Good question! The main difference is context. Plugins tend to be abstracted away from themes and are made in a theme agnostic way. Theme components are usually helper functions that can be used by themes. They serve to make the reuasability of plugins available to code that belongs in a theme.

How do you prepare a theme for theme components?

  1. Download the components helper and drop the components.php file into your theme directory.
  2. Include the components.php file in your theme functions.php file (or other PHP file).
    If including the file using a callback, make sure it is hooked onto after_setup_theme no later than priority of -1000.
  3. Voila!

How do you install theme components?

Simply copy a component folder into the theme-components folder in your theme directory.

How do you create a theme component?

  1. Create a folder inside the theme-components with the name of your component.
  2. Inside your component folder, create a component.php file. This is your main component file (similar to a functions.php file).
  3. As a best practice, declare the namespace WP_Theme_Components\My_Component_Name
  4. From there, you can add your code snippets.