Skip to main content

Why Use a Child Theme

warning

Editing functions.php can break the entire site if you introduce a PHP error. Make changes on staging first and keep rollback access (SSH + WP-CLI).

What a Child Theme Is (and What It Is Not)

TermMeaningWhere it lives
Parent themeVendor theme you update (GeneratePress)/wp-content/themes/generatepress/
Child themeYour customization layer (update-safe)/wp-content/themes/generatepress-child/
InheritanceWP loads child templates first, then parentTemplate hierarchy behavior
Hooks/filtersPrimary customization mechanismadd_action() / add_filter() in child theme

Key Concepts

  • Update safety: parent theme updates overwrite modified parent files.
  • Team workflow: a child theme can be a Git repo with reviewable changes.
  • Portability: you can move the child theme between environments (local/staging/prod).
  • Scope control: you keep your custom code and assets isolated from vendor code.

How It Works

When a child theme is active, WordPress loads the parent theme first, then loads the child theme. For templates, WP checks the child theme directory first. For behavior changes, you add hooks/filters in the child theme.

flowchart TD
WP[WordPress] --> PARENT[Parent: generatepress]
PARENT --> CHILD[Child: generatepress-child]
CHILD --> CB[Child hooks/filters]
CHILD --> CT["Child templates (optional)"]
CT -->|fallback| PT[Parent templates]

Best Practices

PracticeWhy
Keep the child theme smallSmaller blast radius, easier audits
Prefer hooks/filters over copying templatesLess merge debt on updates
Use Git for the child themeRollback and change history
Add a README with deploy notesHelps future maintainers
Escape output and sanitize inputsSecurity and stability
Version your theme in style.cssMakes deployments and rollbacks traceable

Troubleshooting

SymptomCauseFix
Child theme not selectableMissing Theme Name: headerFix style.css header and re-scan themes
Child theme activates but styling is missingParent style not enqueuedEnqueue parent style in child functions.php
White screen after editPHP syntax errorCheck /usr/local/lsws/logs/error.log and fix functions.php
Template override not appliedWrong file path/nameVerify the parent template name and mirror the path exactly

Self-Check

  1. Explain why editing the parent theme is risky.
  2. Describe three things you would put in a child theme (and one thing you would not).
  3. Outline a safe workflow: staging changes, small commits, and a rollback plan.

Quick Reference

If you need to...Prefer...
Add versioned CSS/JS and small hooksA child theme
Add site features (APIs, schema, CPTs)A site plugin or MU-plugin
Change markup in one spotHooks/Elements before template overrides

What's Next