PHPackages                             gregrickaby/nextjs-wordpress-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. gregrickaby/nextjs-wordpress-plugin

ActiveWordpress-plugin[API Development](/categories/api)

gregrickaby/nextjs-wordpress-plugin
===================================

A plugin to help turn WordPress into a headless CMS.

1.0.6(2y ago)41.7k↓50%2MITPHP

Since Sep 18Pushed 2y ago1 watchersCompare

[ Source](https://github.com/gregrickaby/nextjs-wordpress-plugin)[ Packagist](https://packagist.org/packages/gregrickaby/nextjs-wordpress-plugin)[ Docs](https://github.com/gregrickaby/nextjs-wordpress-plugin)[ RSS](/packages/gregrickaby-nextjs-wordpress-plugin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

Next.js WordPress Plugin
========================

[](#nextjs-wordpress-plugin)

A plugin to help configure WordPress for use as a headless CMS.

This plugin is a companion to the [Next.js WordPress Theme](https://github.com/gregrickaby/nextjs-wordpress-theme) and is intended to be used within the [Next.js WordPress project](https://github.com/gregrickaby/nextjs-wordpress).

---

Download
--------

[](#download)

There are a few ways to aquire this plugin:

### 1) Composer

[](#1-composer)

This is the preferred method of installation.

```
composer require gregrickaby/nextjs-wordpress-plugin
```

### 2) WP CLI

[](#2-wp-cli)

```
wp plugin install https://github.com/gregrickaby/nextjs-wordpress-plugin/archive/refs/heads/main.zip --activate
```

### 3) Download

[](#3-download)

Download the [latest release](https://github.com/gregrickaby/nextjs-wordpress-plugin/archive/refs/heads/main.zip) (.zip) and upload it like any other WordPress plugin.

---

### Activate

[](#activate)

Once installed, activate the plugin.

---

Configuration
-------------

[](#configuration)

There's no configuration necessary. For additional project configuration, please see [the instructions](https://github.com/gregrickaby/nextjs-wordpress?tab=readme-ov-file#6-configure-wordpress) in the [Next.js WordPress](https://github.com/gregrickaby/nextjs-wordpress) repository.

---

Revalidation
------------

[](#revalidation)

If your Custom Post Types and front-end routes differ from this plugin, you'll need to edit `src/classes/Revalidation.php` to match your project.

> ⚠️ Editing a plugin directly means you'll need to re-apply your changes after a plugin update occurs. If you do need to customize, consider forking this plugin and making your changes there.

```
// src/classes/Revalidation.php

/**
 * Configure the $slug based on your post types and front-end routing.
 */
switch ( $post_type ) {
 case 'post': // post type
  $slug = "/blog/{$post_name}"; // front-end route
  break;
 case 'book': // book post type
  $slug = "/books/{$post_name}"; // front-end route
  break;
 default:
  $slug = $post_name;
  break;
}
```

---

### Preview Link

[](#preview-link)

To change the preview links, edit `src/classes/Links.php`.

```
// src/classes/Links.php

 public function set_headless_preview_link( string $link, WP_Post $post ): string {

  // Return the original link if the frontend URL or preview secret are not defined.
  if ( ! $this->frontend_url || ! $this->preview_secret ) {
   return $link;
  }

  // Update the preview link to point to the front-end.
  return add_query_arg(
   [ 'secret' => $this->preview_secret ],
   esc_url_raw( "{$this->frontend_url}/preview/{$post->ID}" ) //
