Which Example Would Be A More Complex Theme And Why

In the Getting Started chapter, you learned the basics of what a theme is and how to get one up and running without code. A no-code approach is perfectly OK for simple themes, but once you want to add things that are not possible in the user interface, you’ll need to start working directly with code.

The first step of customizing theme code is to open the theme in your preferred file editor. You can use any theme for this, even the one you created from the Getting Started chapter.

It’s a good idea to familiarize yourself with what others are doing, so feel free to look at several block themes from the WordPress theme directory.

This document will walk you through what the file and folder structure will look like in a typical block theme.

Files and folders

WordPress themes are nothing more than a collection of various files that rely on different web technologies, such as HTML, CSS, and PHP. Block themes also follow a standard structure in how many of those files are laid out.

At its most basic, a theme’s structure will look similar to the following. Take note of the files/folders marked required because they are necessary for a block theme to work:

  • parts/
    • footer.html
    • header.html
  • patterns/
    • example.php
  • styles/
    • example.json
  • templates/
    • 404.html
    • archive.html
    • index.html (required)
    • singular.html
  • README.txt
  • functions.php
  • screenshot.png
  • style.css (required)
  • theme.json
Refer to more articles:  Which Into The Spider Verse Character Are You

Required files

There are two necessary files for WordPress to recognize your block theme, and you will learn more about these in the coming documentation:

  • style.css (Main Stylesheet): This file is required for configuring theme data, such as its name and description. It can also be used for adding custom CSS.
  • templates/index.html (Templates): The default/fallback template. This is necessary for WordPress to consider this a block theme.

Optional files

A theme can include any number of custom files other than the required list above. WordPress also looks for a few other files and uses them if they are available:

  • README.txt (Theme Review: Files): This is not used directly by the WordPress software. But it is a required file when submitting a theme to the official WordPress theme directory, meant to provide information about the theme to users.
  • functions.php (Custom Functionality): A PHP file that WordPress automatically loads after the theme is initialized during the page-loading process. You can use it to run custom PHP.
  • screenshot.png: A 1200×900 screenshot image of your theme. Used for displaying your theme under Appearance > Themes in the WordPress admin and in the WordPress theme directory (if submitted there). Both .png and .jpg are acceptable file formats.
  • theme.json (Global Settings and Styles): Used to configure settings and styles for the site, integrating with the user interface.

Standard folders

In the example above, there were a few folders included. A theme can have many more folders, but WordPress has designated a few of them for specific features. You will learn more about these folders as you read through this chapter:

  • parts (Template Parts): Houses custom template parts for your theme. Parts are smaller sections that you can include within top-level templates. Often, this will include things like headers, footers, and sidebars.
  • patterns (Block Patterns): Reusable patterns made up of one or more blocks that users can insert via the editor interface. WordPress will automatically register files included in this folder.
  • styles (Style Variations): Variations on the theme’s global settings and styles stored in individual JSON files.
  • templates (Templates): Files that represent the overall document structure of the front-end. Templates are made up of block markup and are what site visitors see.
Refer to more articles:  Which Colleges Require 3 Years Of Foreign Language

Advanced theme structure

In reality, block themes can contain many more files and folders. The more complex the project becomes, the more complex its structure will be.

Let’s add a few extra files and folders to the original example:

  • assets/
    • css/
      • core-site-title.css
    • images/
      • header-background.png
    • js/
      • navigation.js
  • inc/
    • ClassName.php
    • functions-helpers.php
  • parts/
    • footer.html
    • header.html
  • patterns/
    • example.php
  • styles/
    • example.json
  • templates/
    • 404.html
    • archive.html
    • index.html (required)
    • singular.html
  • .editorconfig
  • .gitattributes
  • .gitignore
  • CHANGELOG.md
  • LICENSE.md
  • README.txt
  • functions.php
  • package.json
  • screenshot.png
  • style.css (required)
  • theme.json

Optional folders

There is no limit on what folders may be included, but the above example added two of the most common use cases you’ll come across in WordPress themes:

  • assets (Including Assets): Many theme authors use this folder to store additional CSS, Images/Media, and JavaScript needed for their theme. This folder may also have other names, such as resources or public.
  • inc (Custom Functionality): Themes will often have custom PHP classes or files stored in this folder for additional functionality. This folder may also be seen named as includes, src, and more.

Optional files

This list is nowhere near exhaustive, but it includes some common files used in theme development. (Note: most of the following links lead to external, third-party sites and are not affiliated with WordPress.)

  • .editorconfig (EditorConfig): Used for configuring formatting, such as line endings and spacing, for code editors.
  • .gitattributes (Git: Attributes): Configures attributes with the Git version control system.
  • .gitignore (Git: Ignore): Defines files to ignore when committing code to a Git repository.
  • CHANGELOG.md (Keep a Changelog): A human-readable log of important changes for each release of your theme.
  • LICENSE.md (Theme Review: Licensing & Copyright): Defines the license for the theme. Note that all themes submitted to the WordPress theme directory must be licensed under the GPL v2+.
  • package.json (npm: package.json): Often used to define a build process and development dependencies within a Node environment.
Refer to more articles:  Which Sentence Most Accurately Describes Elections In The United States

Don’t feel discouraged if you do not understand all of these files and their purposes yet. Again, these are entirely optional elements of a developer’s workflow. Feel free to learn more about them at your own pace at a later time.

Code editor view

Here is a quick editor view of a real-world theme with an advanced structure:

Visual Studio Code editor showing the structure of a theme

This is vastly more complex than the basics that this documentation is introducing. The point is that, even when building block themes following standard practices, you will have a lot of freedom to customize things. You may want to integrate with version control systems, add in a build process, and more.

So, consider this documentation the foundation in which you can build upon. But there is no harm in keeping it simple and sticking with the basics.

Related Posts

Which Is Not A Function Of Epithelial Tissue

What is the epithelium? The epithelium is a type of body tissue that forms the covering on all internal and external surfaces of your body, lines body…

Which Animal Has The Best Memory

Memory is the brain’s ability to encode and recall the needed information. In other words, memory – the capacity, which enables the remembrance of events, thought, feeling,…

Which Of The Following Genotypes Is Homozygous

What is homozygous? In genetics, the definition of homozygous is when you inherit the same DNA sequence for a specific gene from each of your biological parents….

Which Lines Are Parallel Check All That Apply

Which Lines Are Parallel Check All That Apply

Parallel lines are the lines that do not intersect or meet each other at any point in a plane. They are always parallel and are at equidistant…

Which Of The Following Is True Of Bloodborne Pathogens

Under OSHA’s Bloodborne Pathogens Standard requirements, all employees are to be regularly trained on the risks of occupational exposure to infectious materials. Workers should have a deep…

Which Leg Wear Anklet

Anklets are the perfect accessory for people who don’t like large flash jewelry.You may be interested Which Royal Caribbean Ships Have Bumper Cars Which Muscle Is Highlighted…