Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 972e9e0

Browse files
committed
Add fallback for tax archive canonical url
1 parent a6915ba commit 972e9e0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

api/wordpress/_global/getPostTypeTaxonomyArchive.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ export default async function getPostTypeTaxonomyArchive(
102102
// Flatten posts array to include inner node post data.
103103
response.posts = posts.map((post) => post.node)
104104

105+
// Use final breadcrumb as alternative canonical URL.
106+
const breadcrumb =
107+
archiveSeo?.breadcrumbs &&
108+
archiveSeo.breadcrumbs.length > 0 &&
109+
archiveSeo.breadcrumbs.slice(-1)[0]?.url
110+
111+
// Manually create fallback taxonomy canonical URL.
112+
const fallback = `${response.defaultSeo?.openGraph?.url ?? ''}/${
113+
postTypes?.[postType]?.route
114+
}/${taxonomy}/${taxonomyId}`
115+
105116
// Structure archive SEO.
106117
response.post = {
107118
seo: {
@@ -110,11 +121,7 @@ export default async function getPostTypeTaxonomyArchive(
110121
archiveSeo?.title ??
111122
`${taxonomyId} - ${response.defaultSeo?.openGraph?.siteName ?? ''}`,
112123
metaDesc: archiveSeo?.metaDesc ?? '',
113-
canonical:
114-
archiveSeo?.canonical ??
115-
`${response.defaultSeo?.openGraph?.url ?? ''}/${
116-
postTypes?.[postType]?.route
117-
}/${taxonomy}/${taxonomyId}`,
124+
canonical: archiveSeo?.canonical ?? breadcrumb ?? fallback,
118125
metaRobotsNofollow: archiveSeo?.metaRobotsNofollow ?? 'follow',
119126
metaRobotsNoindex: archiveSeo?.metaRobotsNoindex ?? 'index'
120127
}

0 commit comments

Comments
 (0)