This project provides a template for developing WordPress child themes using Docker. It incorporates modern development tools like TailwindCSS, Webpack, and Sass. The project also facilitates local HTTPS development by generating SSL certificates and provides utilities to synchronize with a production environment.
- Docker: Containerizes the WordPress environment.
- Webpack: Bundles and optimizes assets.
- TailwindCSS: A utility-first CSS framework.
- Sass: A popular CSS preprocessor.
- BrowserSync: Synchronizes browsers and automatically refreshes pages during development.
git clone https://github.com/jonathanelmgren/elmgren-child-theme project-name
cd project-name
The project name should for simplicity always be the same as the theme name (COMPOSE_PROJECT_NAME).
2.3 Do a search & replace for ec_
to your own function prefix. This is to avoid conflicts with other plugins and themes.
Edit the .env
file in the root directory. Set the necessary environment variables like WORDPRESS_DB_HOST
, WORDPRESS_SITE_URL
, etc. Here are some key variables:
COMPOSE_PROJECT_NAME
: The name of your Docker Compose project, should be the same as your theme.GITHUB_TOKEN
: Your GitHub token, if required.WORDPRESS_DB_HOST
,WORDPRESS_DB_USER
, etc.: WordPress database configurations.MARIADB_ROOT_PASSWORD
,MARIADB_DATABASE
: MariaDB configurations.SYNC_PROD_SSH_USER
,SYNC_PROD_SSH_HOST
, etc.: Details for syncing with the production environment.
GITHUB_TOKEN
is required if the repository is private and this should be defined in your wp-config.php file.
Run the ssl.sh
script to generate a self-signed SSL certificate for local development.
docker/ssl/ssl.sh
Note: For macOS users, the script also adds the certificate to the system keychain. Ensure you have the necessary permissions.
Use Docker Compose to build and run the services.
docker-compose up --build
Once the containers are up and running, you can access the WordPress site via the URL you set in the .env
file (e.g., https://elmgren-child-theme.potato
).
However, it is recommended to start a dev environment using these steps
To sync your local development environment with the production server, use the sync_prod.sh
script. This script fetches the production database and content, excluding the current theme.
docker/sync_prod.sh
If you're importing a database from another environment, you might need to update the URLs to match your local development setup. The zwpmigrate.sh
script helps in this process by updating various WordPress database tables.
NOTE: This shell script runs automatically on database initial load. Do not run it manually unless you know what you are doing.
docker volume rm elmgren-child-theme_db
content
: This directory should contain awp-content.zip
file. This ZIP file should contain thewp-content
directory with all its assets. If you're manually adding content for the initial load, ensure that when unzipped, it results in awp-content
directory structure. If you're using the synchronization script, it will handle the extraction process and create thewp-content
directory structure as needed.sql
: Contains SQL dumps, including the one fetched from the production server during synchronization. If you have a custom database dump, you can place it here for initialization during the container's first startup.
-
Build Production Assets:
npm run build
-
Start Development Mode with Watch:
npm run dev
This will start up a proxy using port 3000 with browsersync, to automatically reload the page when changes are made to the theme files.
For contributions, please create a new branch and submit a Pull Request.