Theme Development Environment Setup
Learning Objectives
- Set up a professional WordPress theme development environment
- Configure Docker for WordPress theme development
- Install and configure essential development tools
- Enable WordPress debugging and error reporting
- Understand the development workflow for theme creation
Introduction
Building a WordPress theme is like constructing a house - you need the right tools, a solid foundation, and a clean workspace. Today, we'll set up your professional theme development environment that will make building themes efficient, enjoyable, and error-free.
Development Stack Overview
Think of your development stack as a multi-layer cake, where each layer serves a specific purpose:
flowchart TD
A[Your Code Editor - VS Code] --> B[Version Control - Git]
B --> C[Container Platform - Docker]
C --> D[Web Server - Apache/Nginx]
D --> E[PHP Runtime - PHP 8.x]
E --> F[Database - MySQL]
F --> G[WordPress Core]
G --> H[Your Theme]
style A fill:#e8f5e9,stroke:#4caf50,stroke-width:2px
style H fill:#fff3e0,stroke:#ff9800,stroke-width:2px
style C fill:#e3f2fd,stroke:#2196f3,stroke-width:2px
Code Editor
VS Code with WordPress extensions for syntax highlighting and IntelliSense
Docker
Containerized environment for consistent development across all machines
Git
Version control to track changes and collaborate with others
Debug Tools
Query Monitor, Debug Bar, and browser DevTools for troubleshooting
Docker WordPress Setup
Docker is like having a portable WordPress server in a box. Let's create a docker-compose.yml file specifically optimized for theme development:
# docker-compose.yml
version: '3.8'
services:
# WordPress container
wordpress:
image: wordpress:latest
container_name: wp_theme_dev
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DEBUG: 1
WORDPRESS_DEBUG_LOG: 1
WORDPRESS_DEBUG_DISPLAY: 1
volumes:
# Mount your theme directory
- ./themes:/var/www/html/wp-content/themes
# Mount uploads for persistence
- ./uploads:/var/www/html/wp-content/uploads
# Custom PHP configuration
- ./php.ini:/usr/local/etc/php/conf.d/custom.ini
depends_on:
- db
restart: always
# MySQL Database
db:
image: mysql:8.0
container_name: wp_mysql
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_ROOT_PASSWORD: rootpassword
volumes:
- db_data:/var/lib/mysql
restart: always
# phpMyAdmin for database management
phpmyadmin:
image: phpmyadmin:latest
container_name: wp_phpmyadmin
ports:
- "8081:80"
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: rootpassword
depends_on:
- db
restart: always
volumes:
db_data:
Project Directory Structure
Organization is key! Here's how to structure your theme development project like a professional:
- 📁 wordpress-theme-dev/
- 📄 docker-compose.yml
- 📄 .gitignore
- 📄 README.md
- 📄 php.ini (custom PHP settings)
- 📁 themes/
- 📁 my-awesome-theme/
- 📄 style.css
- 📄 index.php
- 📄 functions.php
- 🖼️ screenshot.png
- 📁 assets/
- 📁 css/
- 📁 js/
- 📁 images/
- 📁 fonts/
- 📁 template-parts/
- 📁 inc/
- 📁 uploads/ (mounted volume)
- 📁 plugins/ (optional)
This structure keeps your theme files organized and separates concerns - styles in one place, scripts in another, and WordPress templates clearly visible.
WordPress Debug Configuration
Debugging is like having X-ray vision for your code. Let's configure WordPress to show us exactly what's happening under the hood:
<?php
// wp-config.php additions for development
// Enable debugging
define( 'WP_DEBUG', true );
// Display errors on screen (only in development!)
define( 'WP_DEBUG_DISPLAY', true );
// Log errors to wp-content/debug.log
define( 'WP_DEBUG_LOG', true );
// Use dev versions of core JS and CSS files
define( 'SCRIPT_DEBUG', true );
// Save database queries for analysis
define( 'SAVEQUERIES', true );
// Disable automatic updates in development
define( 'AUTOMATIC_UPDATER_DISABLED', true );
// Increase memory limit for development
define( 'WP_MEMORY_LIMIT', '256M' );
// Show template file being used (helpful!)
define( 'WP_TEMPLATE_DEBUG_MODE', true );
Real World Debugging Scenario
Imagine you're building a theme and the homepage shows a white screen. With debugging enabled:
Fatal error: Uncaught Error: Call to undefined function
get_theme_option() in /themes/my-theme/index.php:15
Now you know exactly what went wrong (missing function) and where (line 15 of index.php). Without debugging, you'd be searching blindly!
Essential VS Code Extensions
VS Code becomes a WordPress powerhouse with the right extensions. Think of these as power tools in your workshop:
Must-Have VS Code Extensions
- PHP Intelephense - Professional PHP code intelligence
- WordPress Snippets - Quick WordPress function snippets
- ESLint - JavaScript linting for clean code
- Prettier - Automatic code formatting
- GitLens - Supercharge Git capabilities
- Live Server - Live reload for static files
- PHP Debug - Step-through debugging with Xdebug
- WordPress Hooks IntelliSense - Autocomplete for hooks
// VS Code settings.json for WordPress development
{
"editor.fontSize": 14,
"editor.tabSize": 4,
"editor.insertSpaces": false,
"editor.detectIndentation": false,
"files.associations": {
"*.php": "php"
},
"emmet.includeLanguages": {
"php": "html"
},
"php.validate.executablePath": "/usr/bin/php",
"files.exclude": {
"**/.git": true,
"**/.DS_Store": true,
"**/node_modules": true
},
"prettier.tabWidth": 4,
"prettier.useTabs": true,
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
}
}
Browser Developer Tools Setup
Your browser's DevTools are like a Swiss Army knife for theme development. Let's configure them for WordPress:
flowchart LR
A[Browser DevTools] --> B[Elements Panel]
A --> C[Console Panel]
A --> D[Network Panel]
A --> E[Sources Panel]
B --> B1[Inspect HTML]
B --> B2[Live CSS Edit]
C --> C1[JavaScript Errors]
C --> C2[console.log Output]
D --> D1[Load Times]
D --> D2[AJAX Requests]
E --> E1[Breakpoints]
E --> E2[Step Through Code]
style A fill:#fff3e0,stroke:#ff9800,stroke-width:2px
Essential WordPress Plugins for Development
These plugins are like having a team of assistants helping you build better themes:
Query Monitor
See all database queries, hooks, and conditionals. Your theme's performance microscope!
Debug Bar
Adds a debug menu showing query, cache, and other helpful information
Theme Check
Tests your theme against WordPress standards - like a pre-flight checklist
Show Current Template
Displays which template file is being used - no more guessing!
# Install development plugins via WP-CLI (if using Docker)
docker exec -it wp_theme_dev bash
# Inside container:
wp plugin install query-monitor --activate
wp plugin install debug-bar --activate
wp plugin install theme-check --activate
wp plugin install show-current-template --activate
Version Control Setup
Git is your time machine and safety net. Here's how to set it up for theme development:
# Initialize Git repository
git init
# Create .gitignore for WordPress theme development
echo "# WordPress Core
/wordpress/
# Uploads
/uploads/
# Environment
.env
docker-compose.override.yml
# System Files
.DS_Store
Thumbs.db
# Editor
.vscode/
.idea/
# Dependencies
node_modules/
vendor/
# Build files
dist/
*.map
# Logs
*.log
debug.log" > .gitignore
# Initial commit
git add .
git commit -m "Initial theme development setup"
Git Workflow for Theme Development
# Create feature branch
git checkout -b feature/custom-header
# Make changes to your theme files
# ... edit header.php, style.css, etc.
# Stage and commit changes
git add .
git commit -m "Add custom header with logo support"
# Push to remote repository
git push origin feature/custom-header
Testing Your Environment
Let's verify everything is working correctly:
Practice Exercise
Let's put your environment to the test by creating a simple debugging scenario:
<?php
// index.php with intentional error for testing
<?php get_header(); ?>
<main>
<h1>Test Theme</h1>
<?php
// This will cause an error - undefined function
echo get_theme_setting('color');
?>
</main>
<?php get_footer(); ?>
Practice Assignment
Complete your development environment setup and prepare for theme creation:
- Set up Docker environment with the provided docker-compose.yml
- Install and configure all recommended VS Code extensions
- Create a Git repository for your theme project
- Install Query Monitor and Debug Bar plugins
- Create a test theme that successfully displays "Hello WordPress" with no errors
- Take a screenshot of Query Monitor showing your theme's performance metrics
- Bonus: Set up Xdebug for step-through debugging