DEV Community

Maya
Maya

Posted on

Question about Wordpress and Gatsby

Hi folks, I am just following some tutorials on building a Gatsby site with a Wordpress backend using GraphQL. I was wondering if anybody has done this kind of work for a client. Do you need two domain names and double hosting in this case, one for the WP site and one for the Gatsby site? Can you use the free hosted wordpress.com in this case? Either way, don't you just end up with a duplicate site and how do you redirect traffic to and index only your Gatsby site? Just a lot of confusion...

Discussion (2)

Collapse
jnv profile image
Jan Vlnas

In this setup, you use only WordPress' administration and Gatsby as a front-end for your site. There shouldn't be any public traffic to your WordPress installation, only the editors should have access and whatever server or process is responsible for building your Gatsby site.

Do you need two domain names

You don't need multiple domain names, you can expose WordPress on, for example, subdomain (wp.example.com) or in subdirectory (example.com/wordpress). Or you can use whatever domain the hosting provides you with (e.g. example.wordpress.com).

Do you need […] double hosting in this case, one for the WP site and one for the Gatsby site?

It's not necessary to host Gatsby and WordPress separately, but it will be probably easier. For example, you can use a hosted WordPress solution like WP Engine, WordPress.com, or a shared PHP hosting like Bluehost, DreamHost, Hostgator… and deploy your Gatsby site using static hosting like Netlify, GitHub Pages, Cloudflare Pages, or Gatsby Cloud. You can also build Gatsby site using, for example, GitHub Actions, and upload generated files to the shared hosting.

Can you use the free hosted wordpress.com in this case?

You need to install GraphQL plugins to WordPress to be usable as a data source by Gatsby. This is possible only with the pro plan.

Either way, don't you just end up with a duplicate site and how do you redirect traffic to and index only your Gatsby site?

Make sure to prevent indexing of the WordPress installation by search engines (with robots.txt, for example). Additionally there are more plugins to help you setup the WordPress installation as a headless CMS, like WPGatsby and Headless Mode (which takes care of redirects to the production site).

Anyway, personally I don't recommend using WordPress as a headless CMS (some reasons I recently explained elsewhere), especially if you don't have much experience with this setup. There are many hosted headless CMSs with generous free tiers, so you don't need to care about additional hosting for the CMS.
In my experience, WordPress seems attractive to some clients because the CMS itself is free, but the costs of hosting, maintenance, and additional development work outweigh the cost of a hosted headless CMS eventually.

Collapse
may4eto profile image
Maya Author

thanks a lot for your reply!