I am currently building a headless Next.js wordpress application using Vercel's example.
Currently testing in a local environment at http://localhost:3000
for Next.js and http://wordpress.test
for Wordpress.
So far it's working relatively well. I updated the preview link (preview_post_link
) for wordpress to match the preview API endpoint in the Next.js application and updated Wordpress's site url
to be point to my local Next.js environment.
Once the site url
was updated the visit site
,view post/page
buttons now go to my Next.js app.
However, the problem I am having is that it also seems to have updated the save draft
button. So now when I try to save the draft it tries to go to http://localhost:3000/wp-json/wp/v2/posts/38?_locale=user
, my Next.js app and not Wordpress. Obviously because this link doesn't do anything in Next.js it throws an error.
Is this a bug in Wordpress? Or am I setting the headless URL incorrectly?
Setup
- Wordpress version 6.1.1
- Built my own theme
functions.php
<?php
add_filter( 'preview_post_link', 'the_preview_fix' );
function the_preview_fix($post) {
$post = get_post();
return home_url() . "/api/preview?secret=secret&id={$post->ID}";
}
Plugins
- WPgraphQl version 1.14.0
- WPGraphQL JWT Authentication version 0.4.0
Wordpress settings (No other settings have changed)
- WordPress Address (URL) - http://wordpress.test
- Site Address (URL) - http://localhost:3000