PHP code example of gregrickaby / nextjs-wordpress-plugin

1. Go to this page and download the library: Download gregrickaby/nextjs-wordpress-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gregrickaby / nextjs-wordpress-plugin example snippets


// 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;
}

// 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}" ) // <-- edit this to match your front-end routing!
  );
 }