Use same slug for both category and page (prior to page)
-
In our use-case, we have a category like this:
/parent-category/second-level/third-level/
For some categories, we’ll have a themed top-level page on
/parent-category/
We want this page to have the same slug, so when someone removes a part of the URL, they’ll visit the themed page (instead of the top level category page).
In our case, WordPress Pages Slugs have prior to Woocommerce Categories Slugs.
To achieve this, we’ve added these lines of codes to the plugin on row 485:
// Check if slug exists for a page global $wpdb; $slug_exists = $wpdb->get_var("SELECT count(ID) FROM <code>$wpdb->posts</code> WHERE <code>post_name</code> = '" . $slug . "' AND <code>post_type</code> = 'page'"); if($slug_exists > 0){ continue; }
When the permalinks are being rebuild, it checks if the slug is used by a page. If so, he’ll skip the slug to be used by the Woocommerce Category.
@dholovnia Is it possible to implement this feature in the plugin (ideally with an option the user can activate in the settings?)
- The topic ‘Use same slug for both category and page (prior to page)’ is closed to new replies.