Hi @one3rdnerd,
Yes, of course. You can filter the category slugs tree using ‘permalink_manager_filter_term_slug’ filter:
function pm_shorten_category_base($replacement, $replacement_term, $post, $terms, $taxonomy, $native_uri) {
if($taxonomy == 'category' && $post->post_type == 'post') {
$replacement = preg_replace('/([^\/]+)\/([^\/]+)(.*)?/', '$1/$2', $replacement);
}
return $replacement;
}
add_filter('permalink_manager_filter_term_slug', 'pm_shorten_category_base', 9, 6);
Best regards,
Maciej
Thank you, that worked, is there a way of using %productx_category_flat% to just get the top taxonomy term?
Or would we adjust your code to something like
function pm_shorten_category_base($replacement, $replacement_term, $post, $terms, $taxonomy, $native_uri) {
if($taxonomy == 'category' && $post->post_type == 'post') {
$replacement = preg_replace('/([^\/]+)\/([^\/]+)(.*)?/', '$1', $replacement);
}
return $replacement;
}
add_filter('permalink_manager_filter_term_slug', 'pm_shorten_category_base', 9, 6);
?
Appreciate your help.
Thanks
No worries, I tried that and it worked.
I may have noticed a bug that was tripping me up.
My taxonomy is productx_category but the option to strip special characters was actually changing %productx_category% on the permastructure to productx-category and thus nothing was being detected as the taxonomy for the permalink.
I was thinking “Strip special characters” should only apply to the actual permalinks generated, not your slug in the settings as an underscore for a post type or taxonomy is common, even if it doesn’t display with an underscore on the front end archive.
Let me know.
Hi @one3rdnerd,
The permastructures were sanitized because of a typo in the code. I fixed it in the newest version of plugin (I released it a few moments ago):
https://plugins.trac.ww.wp.xz.cn/changeset/2252304/permalink-manager/trunk/includes/core/permalink-manager-actions.php
Sorry for the inconvenience!
Best regards,
Maciej
Thanks @maciej sounds good. I will update it now.
Ah one issue I found with that function.
It’s also stripping my taxonomy term permalinks down from 3 layers to 1 when your plugin is active but I don’t want these settings to touch taxonomy archives, only single posts.
Any ideas?
Hi @one3rdnerd,
That is strange, because free version of plugin does not include any filters that would allow to change the taxonomy terms’ permalinks.
Does the issue persists when the custom code snippet is disabled? Could you send me a sample archive URL?
Best regards,
Maciej
That’s what I thought.
But once I turned the plugin off my taxonomy permalink structure returned to 3 levels which is how I wanted it.
I think this was resolved after I turned on “auto update permalinks”.
I will report back if I see it again but right now it seems to be resolved showing both permalink structures correctly.
Thanks for your help.