{"id":16540482,"url":"https://github.com/fcwu/isr-blog-nextjs-wordpress","last_synced_at":"2025-07-25T09:35:16.710Z","repository":{"id":232842333,"uuid":"692727909","full_name":"fcwu/isr-blog-nextjs-wordpress","owner":"fcwu","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-17T12:01:15.000Z","size":819,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-14T07:33:42.522Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fcwu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-09-17T12:01:07.000Z","updated_at":"2023-09-17T12:01:18.000Z","dependencies_parsed_at":"2024-04-11T20:02:16.827Z","dependency_job_id":null,"html_url":"https://github.com/fcwu/isr-blog-nextjs-wordpress","commit_stats":null,"previous_names":["fcwu/isr-blog-nextjs-wordpress"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcwu%2Fisr-blog-nextjs-wordpress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcwu%2Fisr-blog-nextjs-wordpress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcwu%2Fisr-blog-nextjs-wordpress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fcwu%2Fisr-blog-nextjs-wordpress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fcwu","download_url":"https://codeload.github.com/fcwu/isr-blog-nextjs-wordpress/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241774243,"owners_count":20018239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T18:52:34.369Z","updated_at":"2025-03-04T03:22:27.951Z","avatar_url":"https://github.com/fcwu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# An Incremental Static Regeneration Blog Example Using Next.js and WordPress\n\nThis example showcases Next.js's [Incremental Static Regeneration](https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration) feature using [WordPress](https://wordpress.org) as the data source.\n\n## Demo\n\n### [https://next-blog-wordpress.vercel.app](https://next-blog-wordpress.vercel.app)\n\n## Deploy your own\n\nOnce you have access to [the environment variables you'll need](#step-3-set-up-environment-variables), deploy the example using [Vercel](https://vercel.com?utm_source=github\u0026utm_medium=readme\u0026utm_campaign=next-example):\n\n[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/cms-wordpress\u0026project-name=cms-wordpress\u0026repository-name=cms-wordpress\u0026env=WORDPRESS_API_URL\u0026envDescription=Required%20to%20connect%20the%20app%20with%20WordPress\u0026envLink=https://vercel.link/cms-wordpress-env)\n\n### Related examples\n\n- [AgilityCMS](/examples/cms-agilitycms)\n- [Builder.io](/examples/cms-builder-io)\n- [ButterCMS](/examples/cms-buttercms)\n- [Contentful](/examples/cms-contentful)\n- [Cosmic](/examples/cms-cosmic)\n- [DatoCMS](/examples/cms-datocms)\n- [DotCMS](/examples/cms-dotcms)\n- [Drupal](/examples/cms-drupal)\n- [Enterspeed](/examples/cms-enterspeed)\n- [Ghost](/examples/cms-ghost)\n- [GraphCMS](/examples/cms-graphcms)\n- [Kontent](/examples/cms-kontent-ai)\n- [Prepr](/examples/cms-prepr)\n- [Prismic](/examples/cms-prismic)\n- [Sanity](/examples/cms-sanity)\n- [Sitefinity](/examples/cms-sitefinity)\n- [Storyblok](/examples/cms-storyblok)\n- [TakeShape](/examples/cms-takeshape)\n- [Umbraco heartcore](/examples/cms-umbraco-heartcore)\n- [Webiny](/examples/cms-webiny)\n- [Blog Starter](/examples/blog-starter)\n- [WordPress](/examples/cms-wordpress)\n\n## How to use\n\nExecute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:\n\n```bash\nnpx create-next-app --example cms-wordpress cms-wordpress-app\n```\n\n```bash\nyarn create next-app --example cms-wordpress cms-wordpress-app\n```\n\n```bash\npnpm create next-app --example cms-wordpress cms-wordpress-app\n```\n\n## Configuration\n\n### Step 1. Prepare your WordPress site\n\nFirst, you need a WordPress site. There are many solutions for WordPress hosting, such as [WP Engine](https://wpengine.com/) and [WordPress.com](https://wordpress.com/).\n\nOnce the site is ready, you'll need to install the [WPGraphQL](https://www.wpgraphql.com/) plugin. It will add GraphQL API to your WordPress site, which we'll use to query the posts. Follow these steps to install it:\n\n- Download the [WPGraphQL repo](https://github.com/wp-graphql/wp-graphql) as a ZIP archive.\n- Inside your WordPress admin, go to **Plugins** and then click **Add New**.\n\n![Add new plugin](./docs/plugins-add-new.png)\n\n- Click the **Upload Plugin** button at the top of the page and upload the WPGraphQL plugin.\n\n![Upload new plugin](./docs/plugins-upload-new.png)\n\n- Once the plugin has been added, activate it from either the **Activate Plugin** button displayed after uploading or from the **Plugins** page.\n\n![WPGraphQL installed](./docs/plugin-installed.png)\n\n#### GraphiQL\n\nThe [WPGraphQL](https://www.wpgraphql.com/) plugin also gives you access to a GraphQL IDE directly from your WordPress Admin, allowing you to inspect and play around with the GraphQL API.\n\n![WPGraphiQL page](./docs/wp-graphiql.png)\n\n### Step 2. Populate Content\n\nInside your WordPress admin, go to **Posts** and start adding new posts:\n\n- We recommend creating at least **2 posts**\n- Use dummy data for the content\n- Pick an author from your WordPress users\n- Add a **Featured Image**. You can download one from [Unsplash](https://unsplash.com/)\n- Fill the **Excerpt** field\n\n![New post](./docs/new-post.png)\n\nWhen you’re done, make sure to **Publish** the posts.\n\n\u003e **Note:** Only **published** posts and public fields will be rendered by the app unless [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode) is enabled.\n\n### Step 3. Set up environment variables\n\nCopy the `.env.local.example` file in this directory to `.env.local` (which will be ignored by Git):\n\n```bash\ncp .env.local.example .env.local\n```\n\nThen open `.env.local` and set `WORDPRESS_API_URL` to be the URL to your GraphQL endpoint in WordPress. For example: `https://myapp.wpengine.com/graphql`.\n\nYour `.env.local` file should look like this:\n\n```bash\nWORDPRESS_API_URL=...\n\n# Only required if you want to enable preview mode\n# WORDPRESS_AUTH_REFRESH_TOKEN=\n# WORDPRESS_PREVIEW_SECRET=\n```\n\n### Step 4. Run Next.js in development mode\n\n```bash\nnpm install\nnpm run dev\n\n# or\n\nyarn install\nyarn dev\n```\n\nYour blog should be up and running on [http://localhost:3000](http://localhost:3000)! If it doesn't work, post on [GitHub discussions](https://github.com/vercel/next.js/discussions).\n\n### Step 5. Add authentication for Preview Mode (Optional)\n\n**This step is optional.** By default, the blog will work with public posts from your WordPress site. Private content such as unpublished posts and private fields cannot be retrieved. To have access to unpublished posts you'll need to set up authentication.\n\nTo add [authentication to WPGraphQL](https://docs.wpgraphql.com/guides/authentication-and-authorization/), first you need to add the [WPGraphQL JWT plugin](https://github.com/wp-graphql/wp-graphql-jwt-authentication) to your WordPress Admin following the same process you used to add the WPGraphQL plugin.\n\n\u003e Adding the WPGraphQL JWT plugin will disable your GraphQL API until you add a JWT secret ([GitHub issue](https://github.com/wp-graphql/wp-graphql-jwt-authentication/issues/91)).\n\nOnce that's done, you'll need to access the WordPress filesystem to add the secret required to validate JWT tokens. We recommend using SFTP — the instructions vary depending on your hosting provider. For example:\n\n- [SFTP guide for WP Engine](https://wpengine.com/support/sftp/)\n- [SFTP guide for WordPress.com](https://wordpress.com/support/sftp/)\n\nOnce you have SFTP access, open `wp-config.php` and add a secret for your JWT:\n\n```php\ndefine( 'GRAPHQL_JWT_AUTH_SECRET_KEY', 'YOUR_STRONG_SECRET' );\n```\n\n\u003e You can read more about this in the documentation for [WPGraphQL JWT Authentication](https://docs.wpgraphql.com/extensions/wpgraphql-jwt-authentication/).\n\nNow, you need to get a **refresh token** to make authenticated requests with GraphQL. Make the following GraphQL mutation to your WordPress site from the GraphQL IDE (See notes about WPGraphiQL from earlier). Replace `your_username` with the **username** of a user with the `Administrator` role, and `your_password` with the user's password.\n\n```graphql\nmutation Login {\n  login(\n    input: {\n      clientMutationId: \"uniqueId\"\n      password: \"your_password\"\n      username: \"your_username\"\n    }\n  ) {\n    refreshToken\n  }\n}\n```\n\nCopy the `refreshToken` returned by the mutation, then open `.env.local`, and make the following changes:\n\n- Uncomment `WORDPRESS_AUTH_REFRESH_TOKEN` and set it to be the `refreshToken` you just received.\n- Uncomment `WORDPRESS_PREVIEW_SECRET` and set it to be any random string (ideally URL friendly).\n\nYour `.env.local` file should look like this:\n\n```bash\nWORDPRESS_API_URL=...\n\n# Only required if you want to enable preview mode\nWORDPRESS_AUTH_REFRESH_TOKEN=...\nWORDPRESS_PREVIEW_SECRET=...\n```\n\n**Important:** Restart your Next.js server to update the environment variables.\n\n### Step 6. Try preview mode\n\nOn your WordPress admin, create a new post like before, but **do not publish** it.\n\nNow, if you go to `http://localhost:3000`, you won’t see the post. However, if you enable **Preview Mode**, you'll be able to see the change ([Documentation](https://nextjs.org/docs/advanced-features/preview-mode)).\n\nTo enable Preview Mode, go to this URL:\n\n```\nhttp://localhost:3000/api/preview?secret=\u003csecret\u003e\u0026id=\u003cid\u003e\n```\n\n- `\u003csecret\u003e` should be the string you entered for `WORDPRESS_PREVIEW_SECRET`.\n- `\u003cid\u003e` should be the post's `databaseId` field, which is the integer that you usually see in the URL (`?post=18` → 18).\n- Alternatively, you can use `\u003cslug\u003e` instead of `\u003cid\u003e`. `\u003cslug\u003e` is generated based on the title.\n\nYou should now be able to see this post. To exit Preview Mode, you can click on **Click here to exit preview mode** at the top.\n\n### Step 7. Deploy on Vercel\n\nYou can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github\u0026utm_medium=readme\u0026utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).\n\n#### Deploy Your Local Project\n\nTo deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/new?utm_source=github\u0026utm_medium=readme\u0026utm_campaign=next-example).\n\n**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file.\n\n#### Deploy from Our Template\n\nAlternatively, you can deploy using our template by clicking on the Deploy button below.\n\n[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/next.js/tree/canary/examples/cms-wordpress\u0026project-name=cms-wordpress\u0026repository-name=cms-wordpress\u0026env=WORDPRESS_API_URL\u0026envDescription=Required%20to%20connect%20the%20app%20with%20WordPress\u0026envLink=https://vercel.link/cms-wordpress-env)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffcwu%2Fisr-blog-nextjs-wordpress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffcwu%2Fisr-blog-nextjs-wordpress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffcwu%2Fisr-blog-nextjs-wordpress/lists"}