WordPress with Composer & Git
Professional project structure and dependency management
Enhanced security with environment-specific configuration
~/Code/
Manage WordPress with Composer
Treat WordPress core, plugins, and themes as dependencies. Composer makes development more reliable, improves team collaboration, and maintains a cleaner Git repository. Our roots/wordpress
package has been installed 15,756,772 times.
Install plugins with Composer
/srv/www/my-site
$ composer require wpackagist-plugin/woocommerce
./composer.json has been updated
- Downloading wpackagist-plugin/woocommerce (9.5.2)
- Installing wpackagist-plugin/woocommerce (9.5.2): Extracting archive
Generating optimized autoload files
Dependencies in composer.json
composer.json
Environment-specific configuration
Use .env files and environment-specific configs to manage different settings for development, staging, and production. Keep sensitive data out of your repository with secure environment variables.
Environment variables
.env
Main configuration
config/application.php
Must use plugin autoloader & automated updates
Force regular plugins to work as must-use plugins with Bedrock's autoloader. Set up automated WordPress and plugin updates using tools like Renovate for worry-free maintenance.
Configure mu-plugins in composer.json
composer.json
Automated updates with Renovate
renovate.json
Enhanced security & production-ready
Bedrock's structure keeps sensitive files out of the web root and provides production-safe defaults. WordPress core and plugins can't be modified in non-development environments.
Better Git repository management
Keep WordPress core and plugins out of version control. Your repository contains only your custom code, configuration, and dependencies list—not hundreds of WordPress files.
Bedrock structure
├── composer.json
├── config
│ ├── application.php # Primary wp-config
│ └── environments
│ ├── development.php
│ ├── staging.php
│ └── production.php
├── vendor # Composer dependencies
└── web # Public document root
├── app # WordPress content dir
│ ├── mu-plugins
│ ├── plugins
│ ├── themes
│ └── uploads
├── wp-config.php
├── index.php
└── wp # WordPress core
Standard WordPress structure
├── index.php
├── license.txt
├── readme.html
├── wp-activate.php
├── wp-admin
├── wp-blog-header.php
├── wp-comments-post.php
├── wp-config-sample.php
├── wp-content
│ ├── index.php
│ ├── plugins
│ └── themes
├── wp-cron.php
├── wp-includes
├── wp-links-opml.php
├── wp-load.php
├── wp-login.php
├── wp-mail.php
├── wp-settings.php
├── wp-signup.php
├── wp-trackback.php
└── xmlrpc.php
|
Bedrock
|
WordPress
|
|
|---|---|---|
| WordPress coding standards1 | ❌ | ✅ |
| Traditional WordPress structure2 | ❌ | ✅ |
| Separate configs per environment | ✅ | ❌ |
| Environment variables | ✅ | ❌ |
| Custom wp-content directory | ✅ | ❌ |
| Composer for managing WordPress installation | ✅ | ❌ |
| Composer for managing WordPress plugins and themes | ✅ | ❌ |
| mu-plugins autoloader | ✅ | ❌ |
| 1. WordPress coding standards are not enforced by default, but can added if that is your preference | ||
| 2. Bedrock leverages functionality that WordPress Core provides and is compatible with most plugins |
Sponsors
Help support our open-source development efforts
Built with Bedrock
Recommendations
I'm a big fan of Bedrock (and all of Roots in general)
Bedrock is like the bridge between WordPress and the rest of PHP
In my opinion, the roots.io toolkit is the most sane way to do WordPress in 2023
Roots' distros have been essential to jumping back into WordPress devel after a decade out. Until WP quits being an antiquated, monetized pit of code, this is all that’s holding my sanity in check.
Bedrock is doing a huge service to the WordPress community, and I can see it being adopted as the standard for WordPress development. Hopefully as more people adopt it, the developer community at large will view WordPress sites on similar footing as more “professional” platforms.
If you have to use WordPress, use Bedrock for your web app and Sage to develop your custom theme. Any Laravel developer will feel at home in these tools.
I think 2 years ago I tweeted to y'all to say I love Sage -- now I'm getting started with Bedrock and loving it! thank you for making me feel like WordPress can be sane, secure, and modern.
Subscribe for updates
Join over 8,000 subscribers on our newsletter to get the latest Roots updates and tips on building better WordPress sites
Looking for WordPress plugin recommendations, the newest modern WordPress projects, and general web development tips and articles?