Skip to content
François Thibaud edited this page Oct 30, 2023 · 15 revisions

Folders

The folders structure is defined by the means of the content in it.

Basic structure

The basic structure for the theme is like this :

├── assets
│   ├── acf
│   │   ├── json
│   │   └── php
│   ├── facetwp
│   └── searchwp
├── components
│   ├── gutenberg
│   ├── loops
│   └── parts
├── languages
└── templates

Assets

The assets folder contains all the static code for the configuration of the plugins like

  • ACF
  • SearchWP
  • FacetWP

The goal of theses folders is to handle the .json and .php files needed for the configuration.

Naming

The files naming is for ACF

  • JSON : {group-slug}.json
  • PHP {group_slug}.php

The files naming for SearchWP

  • JSON : config.json

The files naming for facetWP

  • JSON : config.json

Components

Into the components directory we add all the theme files we need, theses files are bits of code included into our theme with get_template_part function.

gutenberg

The gutenberg folder contains all the gutenberg blocs you want to render in PHP.

Naming

The template names into gutenberg is free but it's strongly recommended to create sub-folder based on context like components/gutenberg/{plugin}/{filename}.php

  • components/gutenberg/beapi-summary/summary.php.
  • components/gutenberg/beapi-products/product-1-1.php
  • components/gutenberg/beapi-products/product-1-4.php
  • components/gutenberg/beapi-products/product-1-thumbnail.php

loops

The loops folder contains everything that is between while(have_posts()): the_post() ... endwhile.

Naming

The name of the files have to be {post_type}.php, so if I want to add a template for the event post_type I will create a file like this components/loops/event.php

parts

The parts folder will contain all the specific parts for our theme used for one specific post_type or context.

Naming

The template names into parts is free but it's strongly recommended to create sub-folder based on context or post_type like components/parts/{post_type}/{filename}.php

  • components/parts/event/metadata.php
  • components/parts/event/header.php
  • components/parts/event/footer.php

If there is shared parts, so there is two solutions

  1. put in the components/parts/ folder directly and create a shared directory
  2. move it into the blocs directory on his own folder

templates

The templates directory is used for the WordPress template system. Because WordPress only scan 1 folder depth, this is not possible to add a new folder into this one.

Naming

The naming is mainly free, but it's recommended that we use the post_type first since WordPress allow custom post types templates when multiple post_types are involved there is no need to specify the post_type into the filename.

So we can have

  • templates/page-fullwidth.php
  • templates/post-iframe.php
  • templates/iframe.php

languages

The language folder contains every translation, this is mandatory to have a {text-domain}.pot file into this directory. The post file can be generated with wp-cli i18n command. Every language translated into this directory have to be like

  • {locale}.mo
  • {locale}.po

The best practise is to centralize all the translations into the wp-content/languages/ directory allowing users to edit them without touching the theme itself with, for example, loco translate plugin.