Using Composer to Manage WordPress Themes & Plugins

What is Composer?

Composer is a dependency manager for PHP projects, allowing you to automatically manage your project’s dependencies and packages via the command line. There are tonnes of packages out there that you can include in your projects using Composer, making it a breeze.

Composer, therefore, is great for your everyday PHP projects – but you can also use composer to manage WordPress plugins and themes, too!

Packagist is the main Composer repository which will be used by default when you’re including packages in your projects, however the excellent WordPress Packagist from Outlandish acts as a repository for the WordPress theme and plugin SVNs.

Using Composer with WordPress

Let’s start with a fresh WordPress installation. Grab your copy from wordpress.org and set it up. Then, in the root of your WP installation, create the following `composer.json` file:

You can change your `composer.json` file if you need to, but the important part is the `repositories` object which will make sure we use WP Packagist.

Next, let’s grab a copy of Composer so we can use it. Run `curl -sS http://getcomposer.org/installer | php` and once it’s downloaded, simply run `php composer.phar install` to install your specified plugins or themes. In this example, we’ll be downloading the Mobius Conversion Tracker plugin.

That’s it! If you check out your `wp-content/plugins` folder, you should now see our conversion tracker plugin has been downloaded and installed to WordPress.

Now you can easily make sure your dependencies are up to date by running `php composer.phar update`. Composer will scan for changes, and download the latest version if there is one.