Installing WordPress with Composer used to be painful. Today it is simple and clean. Here is how to manage the WordPress core and its plugins entirely through Composer.
The WordPress core
The johnpbloch/wordpress project tracks the latest WordPress releases and is still the most used. In composer.json, you set the package and the install directory:
{
"require": {
"php": ">=8.1",
"johnpbloch/wordpress": "^6.4"
},
"extra": {
"wordpress-install-dir": "wp"
}
}Then:
composer install
WordPress now sits in the wp folder.
Installing plugins in the right place
By default, other packages land in /vendor. To put plugins and themes where WordPress expects them, you rely on composer/installers, which recognises these types among others:
wordpress-plugin→wp-content/plugins/{$name}/wordpress-theme→wp-content/themes/{$name}/wordpress-muplugin→wp-content/mu-plugins/{$name}/
WordPress Packagist
WordPress Packagist exposes every plugin and theme from the official repository as Composer packages. You add the repository, then the plugins you want:
{
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org"
}
],
"require": {
"php": ">=8.1",
"johnpbloch/wordpress": "^6.4",
"wpackagist-plugin/advanced-custom-fields": "*"
},
"extra": {
"wordpress-install-dir": "cms",
"installer-paths": {
"cms/wp-content/plugins/{$name}": ["type:wordpress-plugin"]
}
}
}Since WordPress is installed in cms here, the installer-paths block tells Composer to place plugins there too. The result: plugins end up in the right place and you activate them as usual from the admin dashboard.
