Consider Implementing a Custom Blocks Parser to Rewrite Internal Link URLs #843
Replies: 3 comments
-
@apmatthews This is something we should be handling in the WP plugin. |
Beta Was this translation helpful? Give feedback.
-
@blakewilson @kellenmace What do you think about moving all URL rewrites to the front-end? 🤔 For Next.js in particular, we already need a parser that can transform internal links to If we did introduce a parser, it could also search any GraphQL query results for the
@kellenmace The server-side block parser you provided works great and I am still completely open to pulling that in. Just wanted to see if your approach would differ if we used the need to replace anchor tags with |
Beta Was this translation helpful? Give feedback.
-
@apmatthews Thanks for this. Some thoughts – As you likely know, our WP Headless plugin currently assumes that the WordPress backend is being used for a single web client (rather than multiple) and requires the user to enter their You mentioned rewriting URLs stored in metadata too. It seems like that could be done on the server using WP's I like the idea that the JSON data that the WP backend serves up is already correct. I should be able to do this:
If we let the WordPress server continue to serve up the incorrect URLs and leave it to the client to rewrite them, then that work would need to be done separately and repeatedly in the web client, iOS client, Android client, desktop app client. etc. My preferred approach is to have the WP backend serve up already correct, rewritten URLs, then use an HTML parser in the frontend Faust app to convert internal link anchor tags to Next.js The approach I use in that blog post does the URL rewrites on the server, and also tacks on an extra What do you think? Am I overlooking any other details we should consider here? Thanks! 👍 cc: @blakewilson |
Beta Was this translation helpful? Give feedback.
-
Currently, the
wpe_headless_content_replacement()
function inwpe-headless/includes/replacement/callbacks.php
handles rewriting internal link URLs so that they have the domain of the frontend app.Because that relies on a
the_content
filter, it works for frontend apps that query the post'scontent
. It does not, however, work for projects that use the WPGraphQL Gutenberg plugin and query forblocks
.We should consider including a custom blocks parser that performs the internal link URL string replacement, similar to this one: https://github.com/kellenmace/headless-block-parser/blob/main/headless-block-parser.php. Then internal links inside of Gutenberg blocks would be properly rewritten, as well.
Beta Was this translation helpful? Give feedback.
All reactions