@sfkislev Welcome to the Community! 
Funnily enough I actually did this myself over the weekend for a project, and it worked fine.
Sharing my configuration, in case it’s helpful:
`robots.ts`
import type { MetadataRoute } from "next/types"
const SITE_URL = "URL"
export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: "*",
allow: "/",
},
sitemap: `${SITE_URL}/sitemap.xml`,
}
}
`sitemap.ts`
import type { MetadataRoute } from "next/types"
const WORDPRESS_API_URL = "URL"
const SITE_URL = "URL"
// Define types for WordPress content
interface WordPressPost {
id: number
slug: string
date: string
modified: string
link: string
}
// Fetch posts from WordPress
async function fetchPosts(page = 1, perPage = 100): Promise<WordPressPost[]> {
try {
const res = await fetch(
`${WORDPRESS_API_URL}/posts?page=${page}&per_page=${perPage}&_fields=id,slug,date,modified,link`,
{ next: { revalidate: 3600 } },
)
if (!res.ok) {
throw new Error(`Failed to fetch posts: ${res.status}`)
}
const posts = (await res.json()) as WordPressPost[]
const totalPages = Number.parseInt(res.headers.get("X-WP-TotalPages") || "1", 10)
if (page < totalPages && page < 10) {
// Limit to 10 pages to avoid too many requests
const nextPagePosts = await fetchPosts(page + 1, perPage)
return [...posts, ...nextPagePosts]
}
return posts
} catch (error) {
console.error("Failed to fetch WordPress posts:", error)
return []
}
}
// Fetch pages from WordPress
async function fetchPages(): Promise<WordPressPost[]> {
try {
const res = await fetch(`${WORDPRESS_API_URL}/pages?per_page=100&_fields=id,slug,date,modified,link`, {
next: { revalidate: 3600 },
})
if (!res.ok) {
throw new Error(`Failed to fetch pages: ${res.status}`)
}
return (await res.json()) as WordPressPost[]
} catch (error) {
console.error("Failed to fetch WordPress pages:", error)
return []
}
}
// Create a URL that uses the main domain
function createUrl(wpUrl: string): string {
try {
// Extract the path from the WordPress URL
const urlObj = new URL(wpUrl)
const path = urlObj.pathname
// Create a new URL with the main domain
return `${SITE_URL}${path}`
} catch (error) {
console.error("Error creating URL:", error)
return wpUrl
}
}
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
// Fetch all posts and pages
const [posts, pages] = await Promise.all([fetchPosts(), fetchPages()])
// Create sitemap entries for posts
const postEntries = posts.map((post) => ({
url: createUrl(post.link),
lastModified: new Date(post.modified || post.date),
changeFrequency: "weekly" as const,
priority: 0.6,
}))
// Create sitemap entries for pages
const pageEntries = pages.map((page) => ({
url: createUrl(page.link),
lastModified: new Date(page.modified || page.date),
changeFrequency: "monthly" as const,
priority: 0.8,
}))
// Add homepage and feed
const staticEntries = [
{
url: SITE_URL,
lastModified: new Date(),
changeFrequency: "daily" as const,
priority: 1.0,
},
{
url: `${SITE_URL}/api/feed`,
lastModified: new Date(),
changeFrequency: "daily" as const,
priority: 0.8,
},
]
// Combine all entries
return [...staticEntries, ...pageEntries, ...postEntries]
}
It could be helpful to look at your current set up!