Using NextGEN Gallery with Bedrock

Recently we decided to migrate all of our older WordPress websites to Bedrock. If you haven’t used Bedrock before, you should know that it’s basically a more solid foundation that comes with a better project structure, Composer integration, easy deployments using Capistrano, and so on. We’re using it for virtually all of our new WordPress websites.

We ran into an issue regarding the NextGEN Gallery plugin which at the moment is not compatible with Bedrock. Unfortunately one of our client’s websites – namely Scoala59.ro – is using it and we couldn’t really find an easy way to replace it. There are some alternatives but none of which are compatible with Bedrock and offer an easy way to import the images and albums. If you know any such plugin, do let us know :).

The incompatibility comes from the way the plugin stores its photos. More precisely, it’s using the WP_HOME constant instead of WP_SITEURL as described here. Since we are using bedrock-capistrano for deployments, it’s easy to setup the plugin’s folder as shared inside the deploy.rb file:

set :linked_dirs, fetch(:linked_dirs, []).push('web/app/uploads').push('web/wp/wp-content/gallery')
Code language: Ruby (ruby)

So besides the usual “web/app/uploads”, we are also adding the “web/wp/wp-content/gallery” folder. This should normally be enough, only that the “web/wp” folder is where Composer downloads and installs WordPress, basically overwriting our new folder. The trick is to create it again once Composer finishes:

# Create symlinks again because Composer removes our web/wp/wp-content/gallery symlink. namespace :deploy do task :fix_symlinks do Rake::Task[ 'deploy:symlink:linked_dirs' ].reenable # Allow the task to be run again Rake::Task[ 'deploy:symlink:linked_dirs' ].invoke end end after 'deploy:finished', 'deploy:fix_symlinks'
Code language: Ruby (ruby)

And that’s it! It took a while to figure out, but now NextGEN Gallery is happily running alongside Bedrock.