How to change the /blog URL path

Creating a website with a blog is effortless with SanityPress. Out of the box, the blog homepage and individual posts are organized under the /blog
URL path.
But what if "blog" doesn’t align with your vision? No problem—customizing it to fit your needs is a breeze with a few tweaks to your SanityPress codebase.
In this guide, we’ll walk you through the steps to update the blog’s URL path. For this example, we’ll show you how to change /blog
to /press
. Let’s dive in!
GROQ queries to update🔗
7 files:
// line 30
- destination.internal->._type == 'blog.post' => '/blog/',
+ destination.internal->._type == 'blog.post' => '/press/',
// line 10
- !(metadata.slug.current in ['404', 'blog/*']) &&
+ !(metadata.slug.current in ['404', 'press/*']) &&
// line 21
- 'url': $baseUrl + 'blog/' + metadata.slug.current,
- 'url': $baseUrl + 'press/' + metadata.slug.current,
// line 26
- !(metadata.slug.current in ['index', 'blog/*'])
+ !(metadata.slug.current in ['index', 'press/*'])
// line 38
- !(metadata.slug.current in ['index', 'blog/*'])
+ !(metadata.slug.current in ['index', 'press/*'])
// line 63
- query: groq`*[_type == 'page' && metadata.slug.current == 'blog/*'][0]{
+ query: groq`*[_type == 'page' && metadata.slug.current == 'press/*'][0]{
// line 15
- 'blog': *[_type == 'page' && metadata.slug.current == 'blog'][0]{
+ 'blog': *[_type == 'page' && metadata.slug.current == 'press'][0]{
// line 68
- !(metadata.slug.current in ['404', 'blog/*']) &&
+ !(metadata.slug.current in ['404', 'press/*']) &&
// line 17
- pathname: '/blog',
+ pathname: '/press',
String values to update🔗
5 files:
// line 31
- 'application/rss+xml': '/blog/rss.xml',
+ 'application/rss+xml': '/press/rss.xml',
// line 13
- const segment = page?._type === 'blog.post' ? 'blog' : null
+ const segment = page?._type === 'blog.post' ? 'press' : null
// line 25
- route: '/blog/:slug',
+ route: '/press/:slug',
// line 17
- const segment = _type === 'blog.post' ? '/blog/' : '/'
+ const segment = _type === 'blog.post' ? '/press/' : '/'
// line 110
- (['blog', 'blog/*'].includes(slug) && VscEdit) ||
+ (['press', 'press/*'].includes(slug) && VscEdit) ||
One last step🔗
Lastly, we want to change the folder name that handles the Next.js routing for the blog pages:
- 👇 src/app/(frontend)/blog/*
🆕 src/app/(frontend)/press/*
Let us know below if you'd like further refinements!
