Managing WordPress Development With Symlinks

By Daniel Pataki Updated on July 14, 2018
242
Shares

In this article, I’ll show you a great way to share a single instance of a plugin or theme with multiple installations of WordPress – symlinks.

A symlink – or symbolic link – is a special file that is actually a reference to another file or folder. If you’re a Windows user you probably already use Desktop shortcuts which are a kind of symlink since they point to a file somewhere else on your system.

The key to us is that they can point to folders as well. Since WordPress 3.9 symlinks have been allowed for plugins and themes which allows us to store them elsewhere and hook them up to our installs.

Looking for ways to improve your WordPress development workflow?

Kinsta’s hosting solution was built by developers for developers. Git, PHP 7, SSH, and WP-CLI, along with powerful staging and cloning environments gives you the tools you need to build sites faster!

Let’s assume that you have a localhost setup with a root directory. Each directory within is a separate WordPress installation. Normally you would install your new plugin in all of them. An error found in one would need to be changed everywhere, making the process long and error-prone.

With symlinks you can keep your plugins and themes in a separate folder and – using symlinks – you can point it into each installation you have. Each installation uses the same files which makes modifications and maintenance a breeze.

If you have multiple domains on the same server you can pull off the same trick. As long as the files for your websites occupy the same file system and your environment allows for symlinks (most do), you can use this method.

My favorite use for this method is handling themes and plugins from Github repositories. I prefer using git as my version control system and my projects have a structure which puts the actual theme/plugin in a sub-directory.

This means that I can’t use the folder as-is in the wp-content folder. Normally I would have to manually copy-paste the changes into the repo or change the repo’s structure. With symlinks I can just symlink the folder I need.

The process of creating a symlink is the same on Windows and Linux based systems (like OSX), but the syntax is a little different. When creating them you’ll need to specify the location of the symlink and the target.

In our case, the location of the symlink will be a folder in the themes or plugins directory. The target will refer to the directory that contains the actual plugin/theme files.

Let’s look at an example where we would use a symlink to link to a plugin in a separate folder. In the example, the root of our project contains multiple WordPress installations and a projects directory which contains plugins and themes.

Symlinks on Windows

Let’s assume that the root directory for our web projects is in C:/websites. You’ll need to open the command prompt and navigate to a WordPress install’s plugin folder and within that folder issue the following command:

mklink C:\websites\projects\my-plugin-github\my-plugin\trunk my-plugin

This command will create a my-plugin folder in your plugins folder which will lead to the folder at C:\websites\projects\my-plugin-github\my-plugin\trunk. When loading the plugin list and processing code WordPress will follow this symlink, making it seem like you have a regular plugin.

Symlinks on OSX and Linux

Let’s assume that the root directory for our web projects is in /Users/danielpataki/websites. You’ll need to open the terminal and navigate to a WordPress install’s plugin folder and within that folder issue the following command:

ln -s /Users/danielpataki/websites/projects/my-plugin-github/my-plugin/trunk my-plugin

This command will create a my-plugin folder in your plugins folder which will lead to the folder at /Users/danielpataki/websites/projects/my-plugin-github/my-plugin/trunk. When loading the plugin list and processing code WordPress will follow this symlink, making it seem like you have a regular plugin.

Summary

You can repeat the process as needed for all your WordPress projects on the same system. At the end of the day, all your installations will use the same files so you can fix a bug once and see it disappear from all WordPress installs.

I use this method a lot in my day-to-day programming. If you do too and you have some tricks up your sleeve, or you have a better way of doing things, let us know in the comments below!

If you enjoyed this article, then you'll love Kinsta's WordPress hosting platform. Whether it's speeding up your website or getting 24x7 support from our veteran WordPress team, we're here to help your business succeed. Our Google Cloud powered infrastructure focuses on auto-scaling, performance, and security. Let us show you the Kinsta difference! Check out our features

Hand-picked related articles

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.
  1. Gravatar for this comment's author
    John November 23, 2017 at 9:55 am

    This is a really interesting article and it got me thinking.

    We run a web design studio and offer hosting within the package. Let’s just say for arguments sake that you have 100 clients. Using this technique could you set those clients up on hosting and have 1 central location for all the plugins and themes on those client sites?

    Because if so then that would save a ton of work in terms of maintaining an updating all those sites.

    Something I’m missing or would it be that simple?

    Thanks!

  2. Gravatar for this comment's author
    Greg January 25, 2018 at 10:52 pm

    I just tried this and it’s awesome, however the WordPress updates don’t seem to work with it – I tried to update a plugin that I had symlinked and WordPress moved the plugin folder out of the source folder and into its normal wp-content/plugins folder, which destroyed the symlink. Is there any way to make WordPress updates obey the symlink and copy to the source directory instead?

    1. Gravatar for this comment's author
      Henrique February 24, 2018 at 6:28 am

      This symlink strategy is only for plugin development workflow.

      I think you should not use this to manage third-party plugins installations. For this, a tool like wp-cli maybe more appropriate.

      https://developer.wordpress.org/cli/commands/plugin/update/

  3. Gravatar for this comment's author
    UgoChukwu March 10, 2018 at 12:17 pm

    Thanks for this article. I am looking for a way to speed up my site by easing the plugin loads on my main server. In that case, have the plugins file load in another server. Then I stumbled on this your article. But going through the comments and your response, it happens not to be favorable for third party plugins.
    Do you have a better solution to install plugins on a different server, and use it in another server, while the server it is installed on handles the load?

Leave a Reply

Use WordPress?

Use WordPress?

Join 20,000+ others who get our FREE weekly newsletter with WordPress tips on how to drive more traffic and revenue to your business!

Consent

You have Successfully Subscribed!

Send this to a friend