1

I have problem with wordpress rewrite and SEO, mostly the sitemap. I'm using the Yoast SEO plugin.

I use the regular "post" post type with two taxonomies. The regular "category" and a cutom taxonomy called "city".

register_taxonomy('city', 'post', array(
    'hierarchical' => true,
    'show_admin_column' => true,
    'query_var' => 'city',
    'rewrite' => array(
      'slug' => 'city',
      'with_front' => true,
      'hierarchical' => true
    )
  ));

This leads to the taxonomy-city.php file. No problem so far. But I wanted to create a cutom url, which has both taxonomies, like: www.url.com/city/some_city/some_category

$wp_rewrite->add_rule( 'city/([^/]+)/([^/]+)/?$', 'index.php?city=$matches[1]&cat=$matches[2]', 'top' );

Which makes this request also load the taxonomy-city.php file. Everything was working, but when I checked the seo titles, canonical tags and the sitemap, they dual category pages are not recognized as a separate page, just the same as the /city/some_city/ url. I solved the canonical tag and meta tag problems, but the sitemap is a bigger problem, because they are missing from the sitemap.

I see two possible solutions, couldn't make any of them work.

  • One of them is that I add new entries to the sitemap, but couldn't find any hook to do this.
  • The other one is, that I make wordpress somehow recognize this combination as a regular page. Perhaps make a connection between the two taxonomies. I tried a lot of things, for example sending the redirect to the category.php file or adding a permastruct to the city taxonomy containing the category as well. Nothing seems to work.

Can someone give me a hint, at least which path should I go forward or am I missing something obvious here? Thanks.

  • How would you generate the URLs to these term combinations to add to a sitemap? Do you really need additional URLs that lead to the same content as the individual term URLs, or are you trying to replace those with these new URLs? – Milo Oct 11 '15 at 9:33
  • I need new URLs for these. so I need: /category/some_category, /city/some_city and /city/some_city/some_category. All three are different. – JuhG Oct 11 '15 at 15:33
  • How would you generate the URLs to these term combinations to add to a sitemap? – Milo Oct 11 '15 at 16:57
  • That is exactly my question. One workaround I see is if I create a new fake taxonomy just for the sitemap. But it feels wrong. – JuhG Oct 11 '15 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.