Theme
This is the main page of the guide for creating themes (templates) for WordPress. The primary information is taken from the official guide and from personal experience.
To immediately see the general principle of creating a theme, go to the handbook section: Creating the simplest theme
What is a theme?
A WordPress theme is a set of CSS, JS, PHP files that, in combination with WordPress and plugins, display information from the database on the screen in a beautiful and convenient way (design). Or in an ugly and inconvenient way, depending on the theme chosen... In other CMS, a theme is also called a "template," but in WordPress it is customary to use the term "theme," not "template." Although in essence, both are the same...
So, if you change the theme, the site changes its appearance. There are thousands of free themes on WordPress.org. Despite the wide selection of themes, many prefer to create their own themes. This is primarily due to the fact that creating a simple theme is not difficult.
Required files
To create a theme, only two files are necessary:
- index.php - the main theme file responsible for displaying content
- style.css - the main style file responsible for CSS styles
But in fact, no theme consists of only two files. There are more: PHP files, language files, CSS and JS files, text files. A theme starts with two files, and then, to make it more convenient, it is expanded by adding files such as:
- header.php - responsible for displaying the header
- footer.php - responsible for displaying the footer
- sidebar.php - responsible for displaying the sidebar
- page.php - responsible for displaying a single page (post)
- and so on. See the full list.
Theme capabilities
The capabilities of a theme are essentially limitless because you can fully use PHP in it. BUT! The theme is intended to display the content of the site in a certain way, not to add functionality to the site. Therefore, the capabilities of the theme are usually limited to those that are responsible for the appearance, and all other capabilities such as voting, ratings, redirects, SEO, etc., are usually outsourced to plugins...
Thus, a theme can:
- Be responsible for displaying the site's content for different types of devices: monitors and smartphones. Such themes are called adaptive. Themes can also be fixed, single-column, two-column, etc.;
- Display any content;
- Specify which content will be displayed for different users;
- Use any design elements (images, videos).
Like any website, a theme is not just about color schemes, layouts, and beautiful graphics. Truly high-quality themes are also very functional. The functionality of a theme lies in its flexible customization. That is, it does not add anything new to the site, but can be finely tuned to the owner's taste. For example: setting a background image, changing the colors of elements, customizing menus, and content blocks (widgets).
How is a theme different from a plugin?
From a code perspective, you can say they are the same - you can create a full-fledged plugin in a theme. But from a logical standpoint - they are completely different! The task of a plugin is to add something new to the site, for example, adding a poll. The task of a theme is to display the content, including that poll...
Thus, the theme is responsible for displaying content on the page, while the plugin is needed to implement the site's functionality.
Never add functionality to the theme itself unless there are compelling reasons to do so. If you do, changing the theme will cause the functionality to be lost along with it. For example, if your theme has a cool photo gallery and you change the theme, that cool photo gallery will be lost...
Therefore, any functionality related to editing/adding site content should be developed as a plugin.
Where to download themes?
The themes directory on the WordPress.org website is one of the safest places to download themes. All themes there are checked for compliance with requirements and recommendations.
There are other sources, but usually the themes there are paid. For example, themes can be downloaded from: Creative Market.
Getting started
Now that we have delved into the themes, we can start creating our own theme. The first thing to do is:
- Set up a local development environment.
- Then you can look at example WordPress themes.
- And start developing your first theme.
--
This section is under development... And in general, I started writing it and abandoned it, finding it uninteresting. If I have time and desire, I will continue...