First of all, symlinks are very useful for when you’re developing and testing something locally. For example, a WordPress plugin. Typical setup in this case would be a separate plugin folder with all the developers tools, libraries and sub-folders plus everything you need to publish it on WordPress.org plugin repository. Of course, not all of this is needed in a production build and you want to test them locally, too. This is where a symlink can really help you out.
In this example, working layout looks likes this:
- A plugin is being developed in a separate folder, “my-plugin”
- Local is used for local environment and runs your local WordPress testing website.
- Symlink is used to make Local think there is actually you plugin in wp-content/plugins folder, while in reality it lives in a separate place.
Now, you might try built-in Finder feature that’s called “Make Alias” but it won’t give you expected result. It will only create a quick link to the original folder but it won’t be enough to actually launch the plugin.
For it to work, you need to create the symlink manually, in a terminal, using
ln command. First address is where your plugin is. Second is where you want the symlink to appear.
ln -s /Users/pavel/Documents/Side\ Projects/my-plugin /Users/pavel/Local\ Sites/test-website/app/public/wp-content/plugins
That’s it! Notice the backslashes – they are necessary for spaces in paths to be read correctly.
Of course, there are edge cases when this setup might not work for you, I found at least one. Please write a comment if you find another one!