Home » How to Create a Blog with NextJS WordPress Starter

How to Create a Blog with NextJS WordPress Starter

by seoshala
Headless-wordpress-development

What is NextJS?

Next.js is a React-based javascript web application framework. Its purpose is to establish a universal framework that allows developers to control the entire lifecycle of their application, from server to client, from a single location.. It offers several features, including a server-side rendering (when available) and static generation, which allows you to export your project as a static app.

How will we use headless WordPress with Next.js?

WordPress comes with a “headless” API that allows us to retrieve material from WordPress using a REST API.

What this implies is that we may continue to use WordPress as usual, but only as an API for our content, which Next.js will utilize to build our site. Furthermore, GraphQL is a WordPress plugin that allows you to query all of your WordPress content using GraphQL, allowing you to handle relationships across your content data in a more powerful and performant way.

What is Next.js headless WordPress Starter?

Next.js WordPress Beginning is a Next.js starter template that includes many of the capabilities you’d expect from a standard WordPress theme, such as full blog support, SEO, and client-side search. The project’s purpose is to develop a standard WordPress blog using modern tools like Next.js, which allows us to create a statically built web app that can be published anywhere. With that in mind, can build a new Next.js project with just one command and a few settings and be up and running with our new Next.js WordPress site in no time!

Step 1: Getting ready as a headless WordPress CMS

Although the content that comes with a WordPress installation is likely enough, it’s always great to get a better image of how your content will be pulled in by adding some test posts or pages.

Step 2: Installing GraphQL APIs to query WordPress with GraphQL

To begin, need to install the GraphQL plugin, which will enable us to use GraphQL to query our headless WordPress data. GraphQL may be readily installed by going to the Plugins section of your WordPress admin dashboard, searching for it, installing it, and activating it.

If you’re already familiar with GraphQL, you can start querying your data inside the GraphQL IDE tab in the admin dashboard navigation after it’s configured! When you’re ready, go to your WordPress site’s /graphql page in your browser, and you should get a GraphQL-related error, indicating that we’re ready to use GraphQL.

Step 3: Creating a new Next.js headless WordPress blog with Next.js WordPress Starter

This step should be very familiar to you if you’ve ever launched a new Next.js website, such as with Create Next App! Go to your terminal and type the following command to build our new website:

yarn create next-app -e https://github.com/colbyfayock/next-wordpress-starter my-blog

# or

npx create-next-app -e https://github.com/colbyfayock/next-wordpress-starter my-blog

This command will take a copy of the Next using the Next.js Create Next App command-line tool. So that we can get started quickly with our project, clone the js WordPress Starter template to a local directory and install all of the dependencies.

Need to create a new file called.env.local within your new project to hold our WordPress API endpoint so our code knows where to get the material from. After you’ve created.env.local in your project, add the following to it:

WORDPRESS_GRAPHQL_ENDPOINT=”[Your WordPress Host]/graphql”

Step 4: Building and deploying a static Next.js headless WordPress blog to Netlify

The goal of the headless WordPress development was to create a fully static WordPress site that could be deployed anywhere. That implies that when we’ve built the site, it’s just HTML, CSS, JavaScript, and any other static files, which we can deploy to our choice static hosting service, such as AWS S3 or Netlify, which we will. To test this out, run the build command using the following:

yarn build

# or

npm run build

The Next.js WordPress Starter already has the build script altered to also export the project to static files, so after it’s run, you can see that Next.js builds the site, then exports it, leaving us with our static files in the out directory. The simplest way to deploy to Netlify is to create a new project on GitHub and connect that repository to Netlify. Any subsequent changes will be redeployed when pushed to GitHub.

Author Bio:– I am Naveen Kumar a digital marketer and product manager. I like to write about WordPress development theme development plugin development. List more articles on free article submission sites.

Related Videos

Leave a Comment