-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Create a custom WordPress sitemap with custom WP-GQL endpoint #121
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahuseyn 🚀 🚀 🚀
LGTM.
Just want to call out and say this is very impressive. The sitemaps look good to me.
I also validated them with xmllint
e.g.
xmllint --noout --debug http://localhost:3000/sitemap/posts/post/1.xml
xmllint --noout --debug http://localhost:3000/sitemap.xml
Thanks @colinmurphy, I appreciate it 🙂 |
Looking good, I think we still need to decide how to address what was expected for this ticket vs this approach. Let's talk tomorrow during refinement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm approving this for general acceptance criteria and content. I have not actually tested and run the code. I think this looks good. I'm debating whether we should have the catch-all route. given this is only suppose to be demonstrating sitemaps, do we ned to render pages? IS it a distraction? but also a front-end with no actual content is kinda weird. I'll leave it to you.
@moonmeister I gave a thought to rendering pages, and experimented with/without it. Without rendering pages the example looked incomplete/partial as the final sitemap links were breaking. Thus I wanted to add a single catch-all route to minimize the distraction. |
Related to: #30
The example includes the @colinmurphy's implementation of wp-env, with custom data and plugins
Which parts need focused attention?
hwpt-wpgraphql-sitemap needs focused attention
Overview
This example demonstrates how to generate a custom sitemap in a headless WordPress application using the Next.js framework. The example app fetches data from WordPress using Apollo Client and WPGraphQL. Since WPGraphQL doesn't support sitemaps natively, we are extending it with a custom plugin, which is included in this example as well. This plugin exposes new fields to fetch the sitemap index, with data identical to what's rendered on the native WordPress sitemap. Another field exposed by this plugin allows you to request sitemap subpages by specifying the types and pages. The plugin also adds featured image data, enabling you to create Image Sitemaps.
The example includes a wp-env setup, which will allow you to build and start this example quickly. With this wp-env setup, you don't need to have a separate WordPress instance or demo data to inspect the example.
Features
/sitemap
requests to/sitemap.xml
, in thenext.config.mjs
Screenshots
After following the installation steps, you should have the example sitemap pages as shown in the screenshots below:
Sitemap index
Posts
Categories
Tags
Users
Pages
Custom post type
Custom taxonomy type
Project Structure
Important notes
Discourage search engines from indexing this site
checkbox underSettings -> Reading
in the WordPress admin.Running the example with wp-env
Prerequisites
Note Please make sure you have all prerequisites installed as mentioned above and Docker running (
docker ps
)Setup Repository and Packages
git clone https://github.com/wpengine/hwptoolkit.git
examples/next/custom-sitemap-apollo/example-app
and add these values inside:or run the command below:
Build and start the application
cd examples/next/custom-sitemap-apollo
pnpm example:build
will build and start your application.wp-env/uploads.zip
towp-env/uploads
which is mapped to the wp-content/uploads directory for the Docker container.example-app
Congratulations, WordPress should now be fully set up.
Command Reference
example:build
example:dev
example:dev:install
example:start
example:stop
example:prune
wp:start
wp:stop
wp:destroy
wp:db:query
wp:db:export
wp-env/db/database.sql
.wp:db:import
wp-env/db/database.sql
.wp:images:unzip
wp:images:zip
Database access
If you need database access add the following to your wp-env
"phpmyadminPort": 11111,
(where port 11111 is not allocated).You can check if a port is free by running
lsof -i :11111