The theme framework can be said to be extremely powerful! For non-technical WordPress users, theme frameworks make it possible to build a website that is unique and looks like it is running a tailor-made theme, and for WordPress developers, they can help you use DRY (dry). Don’t copy yourself) and quickly build a custom website.
If you have used a third-party framework for a period of time and found that its code is bloated and lacks flexibility, and you feel very frustrated about it, or you just want to have full control over your own code, then build your own The theme framework is undoubtedly the best choice!
In this series of tutorials, you will learn how to create your own WordPress theme framework to build a website for yourself or your clients, or publish and share it with other users. You will go through the following stages of learning, including creating a parent theme with the basics of the framework, adding additional functionality, hooks (also called "hooks"), and more. You'll also learn how to use these techniques in your child themes and plugins, how to share your code with the public, and more.
But before you get started, you need to know how theme frameworks work, and what exactly makes them different from a standard parent theme.
I spent some time developing two theme frameworks that were applied to two types of client websites, and I continued to enhance and improve some of their applications over time. I have also worked with third parties to develop some theme frameworks. From my experience, a theme framework should have the following main features:
Points 1 and 2 above are fundamental – without a parent theme, you won’t have a theme framework. A parent theme that does not have those hooks and functions can only be regarded as a basic parent theme, and cannot be said to be a real theme framework.
The above is about theme frameworks, but how do they work? Let’s start by looking at the elements of a theme framework:
AD:Web Studio
Parent theme and child theme
The main component of a theme framework is the parent theme, which can be designed in two ways:
Since one of the key features of theme frameworks is the DRY principle, whenever possible, your parent theme will utilize template parts and include files?, meaning you can access the same code in multiple places in your theme . This also makes it easier to rewrite code in a child theme, since you only need to replace a template component or create an include file.
I will not explain the concepts of parent theme and child theme here for the time being, because it will be introduced in the "Child Theme Tutorial". Although many theme frameworks are equipped with a series of sub-themes that support themselves, if you want to have other sub-themes that are more suitable for you, you have to develop them yourself.
If you are developing your own main framework, I recommend that you create at least one "initial" subtheme to avoid duplicating the work of developing each project: you may decide to create multiple subthemes for different types of projects. Basics, such as some subtopic blogs and non-blog sites.
Action Hooks and Filter Hooks
When adding custom code or changing the way a theme behaves, a theme framework will include a series of hooks that are linked to child themes and plugins:
It’s worth spending some time in the early stages to think about what hooks you want to include, so you know what needs to be included via a hook and what can be written directly into your template file. You will learn about this in the following tutorials.
Functions
Your theme framework may also include a series of functions. Some of these will be hooked into action hooks and filter hooks that you have defined, while others are functions such as template tags, and child themes can use these functions.
If you have used any custom functions on some client websites, then you can add them to your theme framework as well. Also, you don't have to activate all functions: you only need to activate the functions related to the parent theme using the add_action() function on your subsite.
Theme Options
Theme Options interface is useful for any complex theme, especially for non-technical users. Some major theme frameworks include multiple theme options interfaces in their own admin area. Options include switching features, modifying layouts, adding content, and changing design elements such as colors, background images, fonts, title images, etc.
You can choose to use the theme customizer to complete many of your options. The advantage is that it allows your users to directly see their changes while customizing the theme. I did this for the Edupress theme framework, the school website I developed with Mark Wilkinson.
Widget Areas
Whether you need to choose to add a series of widget areas will depend on the audience of your theme framework: if it is only used by yourself or a small team of developers, you may not need to add a series of widget areas. Add any widget area above the standard sidebar and footer.
However, if your theme framework is aimed at non-technical users, you can give it more flexibility by registering multiple widget areas in various places in the theme framework. You can also register widget areas in the site header, standard sidebar and footer, before and/or after content, and below the footer.
The theme framework used by my client website contains four widget areas in the footer: the theme checks which ones are filled and adds CSS classes accordingly, so the filled widget areas will each occupy the appropriate portion of the page width.
Your widget area may be written directly into your template file, or you may decide (like me) to add it via an action hook at a relevant location on your site. This means they can be overridden in child themes, whether as optional widget areas or custom code.
Scripts
If a given script is likely to be used by some websites built on top of your own theme framework, or if your users are non-technical and you want to provide more options, then you You can include specific scripts in your frame, such as a slider or lightbox script. This saves the user from having to install additional plugins, but it can be bloated if the scripts are not actually necessary, which is where it falls short.
Again, this will depend on your audience and expected needs: if it's just a framework you're working with, I recommend using these scripts to develop (or identify) these plugins and use them whenever you need them.
If you actually include these scripts, it is equivalent to including the enable and disable options on the theme options interface.
Scalability
If your framework is currently useful for a certain set of websites, you may want it to be scalable in the future. The parent theme that forms the core of the framework is equivalent to the heart of this ecosystem. You and your theme users will further improve and add more options and features to your website. This will include:
It may also include some useful documentation for other developers who want to use your framework: The most important theme framework comes with extensive documentation that developers can use to customize the websites they build on the framework or for other Users create some child themes or plugins.
Summary
Theme framework is a very powerful tool in the WordPress developer’s arsenal. As we can see, it’s crucial not only for the thousands of non-technical owners who use it to create custom WordPress sites, but also for any other developer out there. tools, whether these developers want to create a variety of websites for themselves or their clients.
Theme frameworks usually have some of these characteristics: extensibility and flexibility, and allow you or your users to easily customize the website by using child themes and accessing related functions and hooks provided by your framework.
We already know how the theme framework works. In the next lessons in this series, you will understand what your framework needs to do, who it needs to work for, etc., and this will help you decide on your theme framework. the most appropriate development path.
Copyright Statement: Please indicate the source URL when reprinting
The above introduces how the WordPress theme framework works, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.