On our latest post we talked about how the new Quema Labs redesign is a Headless WordPress and a new Gatsby site.
This means that every time a new post like this one is published, we have to run a new build for our site to create a new static files from this post. Same goes for every new content on our WordPress site.
If you don’t update your site often, you can just trigger manually a new build directly on your static web hosting like ZEIT Now or Netlify.
But if you are like me and you love to automize things, then keep reading because I will show you how to use a new WordPress plugin to trigger a webhook on your server to start a new build every time a post, page or custom post type is edited or published on your site.
I created a new plugin called WP Headless Trigger, you can go to the Github page and download the latest release.
This is a simple WordPress plugin that triggers a webhook you specify that then will trigger your build command.
So, first download the latest ZIP file from Github, then go to your Admin Panel on your WordPress site, Plugins > Add New > Upload Plugin
Select the ZIP file, install and activate the WP Headless Trigger plugin.
Once you did that, you will see a new page under Tools > Headless Trigger on your menu.
There you have only one input to add your Webhook.
The webhook URL depends on your hosting provider, for example here in Quema Labs we use ZEIT Now. So let’s see where to find our webhook to trigger a new build.
Go to your ZEIT Now dashboard, select your project and go to Settings
There you can create a new Deploy Hook, this is a URL that each time you make a HTTP request it will run a new build script on your project.
Since we are using Gatsby, every time you run a new build, it fetch all the new data from our Headless WordPress and creates the new static files that are served on our site.
So, copy that URL and paste it on the settings page from our plugin WP Headless Trigger and click Save Changes
That’s it, now every time you edit or publish a new post, page or custom post type item, it will trigger that webhook and start a new build script.
This plugin makes even easier to run a Gatsby site with WordPress as a Headless CMS.