Skip to main content

WordPress Coding Guide

We build websites with either WordPress or the Fegg Framework. This guide covers the rules for WordPress sites.

LH WordPress Template​

Every WordPress site starts from the LH WordPress Template. Its theme (htdocs/wp-content/themes/Template/) already has the functions, sample pages and plugin settings described in this guide.

The template's README.md explains how to write each settings file, and its CLAUDE.md gives the same rules to coding agents such as Claude Code.

Design principles​

Theme files are the single source of truth​

So that the test and production environments don't drift apart, everything that defines the structure of the site is written in theme files. Uploading the files is enough to bring any environment to the same state.

  • The database holds content only: body text and the values editors enter.
  • Structure is written in files: which pages exist, custom fields, post types, SEO settings, redirects and forms.
  • Avoid settings that are made on an admin screen and saved in the database. Keep this in mind when you choose a plugin too.
WhatWhere (under the theme)Page
Pagessettings/pages.phpCreating pages
Post types and taxonomiessettings/post-types/*.phpCustom post types
Custom fieldssettings/fields/*.phpCustom fields
SEOsettings/seo.php and othersSEO
Redirectssettings/redirects.phpRedirects
Formssettings/forms/*.phpContact forms

Mechanism and definitions are separate​

  • include/ holds the mechanism. Don't change it per project.
  • settings/ holds the definitions. Edit these per project.

Secrets go in wp-config.php​

Never write API keys or other secrets in the theme. Define them as constants in wp-config.php (e.g. TOFU_RECAPTCHA_SITE_KEY).