Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 67836

Use Canonical URLs in Post Type Sitemap?

$
0
0

Replies: 0

Is it possible to have post type’s sitemap use canonical URLs?

We have a URL requirement that we can’t solve with a Custom Rewrite Slug so we’re leaning on setting Canonical URLs for each of these post types.

Hinging off the canonical URL works for on site links, but removes them from the post type’s sitemap (if I’m understanding everything correctly).

We’d like canonical URLs to be used (exclusively) in the post type’s sitemap.

For clarity, here’s the URL structure we’re using. Our URL for our post type (communities) needs to look like:

/new-homes/{county-name}/{city-name}/{community-slug}

We can’t solve this with a Custom Rewrite Slug for communities, as the {county-name} and {city-name} vary from community to community.

The standard URL for this post would be /communities/{community-slug}

To get our custom URLs mapped correctly to WP I have some custom rewrite_rules. Here’s the relevant one to make the our canonical URL structure work correctly.


// community links, e.g., '/new-homes/davis-county/woods-cross/valentines-estates'
add_rewrite_rule(
  '^new-homes/([\w_-]+)-county/([\w_-]+)/([\w_-]+)'
  ,'index.php?communities=$matches[3]'
  ,'top'
);

Viewing all articles
Browse latest Browse all 67836

Trending Articles