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?
- Download the components helper and drop the
components.phpfile into your theme directory.
- Include the
components.phpfile in your theme
functions.phpfile (or other PHP file).
If including the file using a callback, make sure it is hooked onto
after_setup_themeno later than priority of -1000.
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?
- Create a folder inside the
theme-componentswith the name of your component.
- Inside your component folder, create a
component.phpfile. This is your main component file (similar to a
- As a best practice, declare the namespace
- From there, you can add your code snippets.