Nexcess Logo

How to Use GatsbyJS with Your WordPress Site

Knowledge Base Home

Notice anything different?

We've enhanced the appearance of our portal and we're working on updating screenshots. Things might look different, but the functionality remains the same.
April 20, 2022

By reducing your website complexity by being integrated with headless WordPress, Gatsby can provide enhanced performance and security to leverage site wide.

GatsbyJS with Your WordPress Site

Can I Use WordPress as Headless CMS?

With its worldwide standing as the most popular CMS in use, WordPress is super flexible. Its open-source foundation easily allows you to use WordPress as a headless CMS.

What is a Headless CMS vs. a Traditional CMS?

A headless CMS separates the presentation layer from the content store and system. A traditional CMS integrates the front end and back end closely in the architectural layers.

Using GatsbyJS with Your WordPress Site

WordPress remains one of the most popular content management systems powering more than 30% of websites worldwide. While it can be considered a database-driven system, the development of the Rest API has made it possible to transform the platform into a headless CMS. GatsbyJS is one of the fastest front-end frameworks to use with headless WordPress for various reasons. In this article, we will learn what GatsbyJS is, how to integrate it with your WordPress site and why the concept of a headless CMS opened a new page in website building.  

Overview of the GatsbyJS

GatsbyJS is a fast and reliable frontend framework powered by Jamstack  for building modern websites and applications. As a static content generator, it provides an alternative to database-driven content management systems by generating HTML pages deployed during the build process. WordPress integration with GatsbyJS has made it possible for website owners to leverage all the headless architecture's benefits for making your WordPress site faster and more secure. 

What is Jamstack & How Does It Work with a Headless CMS?

GatsbyJS relies on Jamstack as the architecture powering the static content generator. Jamstack employs Javascript, API, and HTML markup. 

By default, WordPress utilizes PHP for building dynamic web pages, while all content is stored within the database. Web pages are rendered to the visitors by a web server after the requested data is retrieved from the database and merged with template files to generate an HTML page. This approach has been used for a long time and can be considered traditional and reliable.

Once the concept of a headless CMS was presented to the world and WordPress developed the REST API, website building became more flexible. You could choose another programming language to power your WordPress sitelike JavaScript, which has gained popularity over the past years. Headless content management systems return structured data via an API, which means it returns JSON or XML that can be compiled and then optimized by GatsbyJS or any other front-end frameworks. Using Jamstack, you can even host your website without having a web server or database management system. 

WordPress Integration with GatsbyJS: Pros and Cons

Using Gatsby as a Jamstack-powered static content generator to integrate with your WordPress site provides a wide range of benefits. Still, this approach also has its drawbacks that need to be taken into account. Let’s look at the pros and cons of the WordPress integration with GatsbyJS

We can define the three main advantages of using GatsbyJS with your WordPress site:

  • Reduced site complexity. Static content generators significantly reduce your WordPress site complexity by skipping database management in the content rendering process. 

  • Increased speed and reliability. Due to the website’s reduced complexity, your web pages load considerably faster and utilize fewer hosting resources. In addition, GatsbyJS websites can be hosted anywhere; you can serve static content via a Content Delivery Network (CDN) and use an object storage service.

  • Enhanced security. A headless CMS has fewer to no connections to databases or web servers, providing a "smaller attack surface" per se. However, it's important to note that sites powered by Jamstack can still be affected by cross-site scripting attacks.

While it seems like GatsbyJS could be a perfect solution for every WordPress website, several limitations can make you want to stick to the database-driven CMS which WordPress the default scenario.

  • No dynamic content. The system’s reduced complexity can also be considered a disadvantage. GatsbyJS can only serve static content, which means you cannot continue using contact forms or comments on your WordPress website as quickly as before.

  • More technical knowledge required. As GatsbyJS relies on ReactJS and GraphQL, its users need to have at least some basic understanding of the Jamstack.

  • Frequent builds. GatsbyJS is not convenient for frequent changes to the website as changes require running the build process to recompile your website.

GatsbyJS can help you create faster, more secure websites with reduced site complexity and lower costs. The platform is perfect for product demo websites and portfolios. In addition, dynamic websites often require database-driven architecture.

Details Involved with a GatsbyJS & WordPress Integration

The process of WordPress integration with GatsbyJS is pretty straightforward and consists of three main steps:

  1. Set up the development environment.

  2. Install and configure GatsbyJS.

  3. Connect Gatsby to WordPress.

Step #1: Set Up the Development Environment

Installing and configuring the GatsbyJS includes setting up our Gatsby environment and creating a new project. The official Gatsby plugin is a Node.js package, so to have it installed, you need to have Node.js (v14.15 or newer) and NPM installed in your environment. Gatsby also requires Git, so be sure you have the version control system installed. 

The Gatsby Command Line Interface (CLI) is what we need to get started. It can be installed using NPM, as shown below:

npm install -g gatsby-cli

Version 3 or newer is required, so once you install the Gatsby CLI, you can run the gatsby --version command to ensure you have the correct one installed.

Step #2: Install & Configure GatsbyJS

Once we have the Gatsby CLI installed using NPM, we can install the Gatsby solutions for WordPress integration and create our first GatsbyJS project.

First, we need to install two WordPress plugins on our website, WPGatsby and WPGraphQL. The WPGatsby plugin optimizes your WordPress website to be used as a data source for the GatsbyJS. WPGraphQL helps you get started with GraphQL by providing the GraphQL schema and API for WordPress

Once the plugins are installed, we can move on to creating a new GatsbyJS project. Run the gatsby new command to set up a new GatsbyJS website. Here the name of our new project directory is wordpress-site, but you can change it to anything you like. A new GatsbJS site will be created in the wordpress-site directory using the Gatsby starter template. Make sure to move to the new project directory before we can proceed with the Gatsby plugin installation:

gatsby new wordpress-site

cd wordpress-tutorial-site

Now it's time to install the Gatsby Source WordPress plugin. We will again use NPM for its installation:

npm install gatsby-source-wordpress

Step #3: Connect GatsbyJS to WordPress

Once we have the Gatsby Source WordPress plugin installed and the WPGatsby and WPGraphQL plugins added to our WordPress website, we can get a connection established between WordPress and the new Gatsby project. 

Open the gatsby-config.js file using the preferred text editor and modify the url option to connect the GraphQL endpoint you created by installing WPGraphQL in your WordPress installation. By default, it would be https://your-wordpress-website/graphql:

       * First 
up is the WordPress source plugin that connects Gatsby
to your WordPress site.
       * visit the plugin docs 
to learn more
       * http
resolve: `gatsby-source-wordpress`,
s: {
        // the 
only required plugin option for WordPress is the GraphQL url.
          process.env.WPGRAPHQL_URL ||

The GraphQL endpoint is the only thing you need to add to the gatsby-config.js file. Next, it's time to run the gatsby develop command for the Gatsby Source WordPress plugin to fetch all available public data from WPGraphQL. It will only fetch the data that changed to keep builds quick on further builds:

gatsby develop

That’s it! We have connected our new GatsbyJS project to our WordPress website. As a result, we can easily create new page templates and GraphQL queries that will be pulling data from WordPress.

Conclusion: GatsbyJS with WordPress

GatsbyJS is a powerful static content generator that provides an alternative to the database-driven website architecture employed by most WordPress websites. Reducing your website complexity by being integrated with headless WordPress can provide enhanced performance and security to leverage. Additionally, you can set up your production environment and connect your WordPress website to a new or existing Gatsby project with the help of the Gatsby Source WordPress tool. After the connection has been established, you will get access to endless customization possibilities the front-end framework provides.

Consider Managed Hosting with Nexcess

Nexcess has transformed the concept of Managed Hosting to present you with the best solutions for your WordPress website. A faster, more secure, and scalable website is what you are getting when choosing one of the Nexcess Managed WordPress Hosting plans optimized for the platform. We have gathered the best tutorials in our Nexcess Knowledge Base to help you integrate your WordPress website with the most outstanding solutions to enhance your hosting experience and make your life as a website owner more manageable. So check out our Managed WordPress plans to start today!

Useful WordPress Links for Developers & Admins

Hosting Solutions with Nexcess

Hosting optimized for the industry's leading platforms, including Managed WordPress Hosting, Managed WooCommerce Hosting, and Managed Magento Hosting:

Build Better Sites and Stores With Fully Managed Hosting from Nexcess 

Faster Speeds, Stronger Security, Inherent Scalability and Trusted Support.

Our range of hosting plans caters to any business scale. We do all the heavy lifting for you to focus on growing your business. In addition, we automatically update ore components and plugins to the latest version and ensure your hosting environment is properly optimized, secured, and updated.

Nexcess infrastructure was specially designed to keep up the best speed and performance in the industry. No traffic surge can threaten your website to go down thanks to our autoscaling technology which adds more resources to your server to handle the load. In addition, we offer always-on security monitoring and support from web hosting experts 24/7/365 and a built-in CDN with 22 locations and advanced caching for ultra-fast loading.

All hosting plans include The Nexcess 30-Day Web Hosting Money Back Guarantee.

Need a No-Code Website Building Solution? 

Are you on an accelerated schedule and already ready to move forward? If you need to get started with your Nexcess StoreBuilder Solution sooner rather than later, check out these resources:

Next Steps with a Nexcess Cloud Hosting Solution?

Read more about the Fully Managed Cloud Environment by Nexcess and its benefits for your business.

A Cloud Hosting Solution That Lets You Do Business Your Way 

We believe in the promise of cloud: scalability, security, performance, and ease of use. Together with our team, clients, and partners, we’ve built something better.

Choose From Multiple Applications 

Whether you’re a small business or a high-traffic eCommerce store, our cloud hosting solutions are designed around your needs: auto scaling, PCI compliance, and comprehensive development tools provide you with maximum dynamic flexibility in a fully managed cloud environment.

We make applications easy with environment optimizations for:

And there are many more!

We also have a variety of Nexcess support articles about how best to implement our product offerings housed in the Nexcess Knowledge Baseincluding how to get your site going with a number of different configuration options. These resources include a great article on setting this up for Migrating to Nexcess with managed WordPress and managed WooCommerce hosting

Next Steps with Fully Managed WordPress Hosting?

Read more about the Fully Managed WordPress Hosting and its benefits for your business.

Build Better Websites with Fully Managed WordPress Hosting 

It’s hosting optimized for WordPress. That means a faster, more secure and scalable website. Smart monitoring tools are built-in to help you keep it that way. 

It’s why WordPress Users Trust Nexcess Hosting.

We also have a variety of Nexcess support articles about WordPressincluding how to get your site going with a number of different configuration options. These resources include a great article on setting this up for Migrating to Nexcess with managed WordPress and managed WooCommerce hosting

24-Hour Assistance

If you need any assistance with the above-mentioned, don't hesitate to reach out. For 24-hour assistance any day of the year, Nexcess customers can contact our support team by email or through your Client Portal.

Why Choose Nexcess?

Because we're different! Chris Lema captures "the why" in his passionate and stirring recount of a Nexcess support-related story.

Useful YouTube > Nexcess Channel Links

Resources for More Information

Need more help? The Applications, WooCommerceand WordPress sections within the Nexcess Knowledge Base are important resources for those seeking additional knowledge. 

The Applications section also contains valuable insights for those seeking additional knowledge about our other various hosted applications and platforms. Check out our related video playlists and articles below:

New Customers: Fully Managed Hosting Solutions

Not a Nexcess customer yet? Check out our fully managed hosting solutions. The option to chat with an expert is also available.

Related Articles

Kiki Sheldon
Kiki Sheldon

Kiki works as a Security Specialist for Liquid Web. Before joining the Abuse & Security Operations Department, she worked on the Liquid Web Managed Hosting Support Team, where she gained extensive knowledge of Linux System Administration and popular Content Management Systems (CMSs).

Kiki’s passion for writing allows her to share her professional expertise and help others. She keeps up with technology and always looks to improve her technical skills. In her free time, she enjoys reading, especially classic books and detective stories.

We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.