Child Theme Development in WP Rig
WP Rig includes a specialized tool for creating child themes that inherit the core functionality of the parent theme while allowing for customizations.
Configuration & Child Context
Before developing or modifying a child theme, you MUST reference the config/config.json.
- Check Context: Determine if you are operating within a child theme by checking
child.enabled. - Parent Reference: Use
child.parentSlugto correctly reference the parent theme in logic and overrides.
Creating a Child Theme
Use the childify script to scaffold a new child theme.
npm run childify
The script will:
- Prompt for a child theme slug.
- Create a new directory for the child theme in the WordPress
themes/folder. - Copy the necessary assets (
style.css,functions.php,package.json,config/). - Set the parent theme reference in
style.css.
Architecture of WP Rig Child Themes
Child themes in WP Rig are designed to be thin layers on top of the parent theme.
Key Considerations
- Component Overrides: Child themes can override parent components by implementing a class with the same slug.
- Assets: Child themes have their own
assets/directory and build system. - Functions.php: Use
functions.phpfor child-specific hooks or to load child components. - Styles: Child themes automatically enqueue the parent's styles. Add custom styles to the child theme's
assets/css/src/global.css.
Development Workflow
- Scaffold: Run
npm run childify. - Setup Child: Navigate to the new child theme directory (
cd ../{child-slug}). - Install Dependencies: Run
npm installin the child theme directory. - Configure: Update
config/config.jsonin the child theme to set thedevURL. - Develop: Use
npm run dev:modernfrom within the child theme directory.
Best Practices for Agents
- Keep it Thin: Only add code to the child theme that is truly specific to the customization.
- Use Components: If the child theme needs significant new functionality, create a new component in the child theme's
inc/directory rather than overloadingfunctions.php. - Parent Assets: Avoid copying parent assets unless you need to modify them. Use the parent theme's enqueued scripts and styles when possible.
- Theme Slug: Be mindful of the theme slug in your PHP namespace. Child theme components should use a namespace that distinguishes them from the parent theme.
- Testing: Test the child theme's build process (
npm run build) independently of the parent theme.