Hi Kevin,
You will need to use a custom code snippet to make the articles’ permalinks conditional because the plugin allows to specify one permastructure (permalink format) for all posts through the plugin interface.
If you use the inbuilt tags (post_tag taxonomy), the code snippet should look as follow. I am not exactly certain if this would work out-of-box in your specific case, but it should not be difficult to adjust it:
function pm_filter_post_permastructure($permastructure, $post) {
// Filter only 'Post' permalinks
if(empty($post->post_type) || $post->post_type !== 'post') {
return $permastructure;
}
// A. Articles tagged 'business'
if(has_term(array('business'), 'post_tag', $post)) {
$permastructure = 'business/growth-and-strategy/%postname%';
}
// B. Articles tagged 'personal'
else if(has_term(array('personal'), 'post_tag', $post)) {
$permastructure = 'personal/growth-and-strategy/%postname%';
}
return $permastructure;
}
add_filter('permalink_manager_filter_permastructure', 'pm_filter_post_permastructure', 10, 2);
The snippet, it is supposed to dynamically overwrite the permalink settings (“Permastructures”) you have set (if certain condition is met) via the interface.
I have made some adjustments to the code it acts like it is not making any changes at all. Are there any settings in the plugin I need to set?
function pm_filter_post_permastructure($permastructure, $post) {
// Filter only 'Post' permalinks
if(empty($post->post_type) || $post->post_type !== 'post') {
return $permastructure;
}
// A. Articles tagged 'business'
if(has_term(array('business'), 'post_tag', $post)) {
$permastructure = 'business/%category%/%postname%';
}
// B. Articles tagged 'personal'
else if(has_term(array('personal'), 'post_tag', $post)) {
$permastructure = 'personal/%category%/%postname%';
}
return $permastructure;
}
add_filter('permalink_manager_filter_permastructure', 'pm_filter_post_permastructure', 10, 2);
All modifications to permalink formats (Permastructures) are only applied to new items (posts) by default. To set it for existing post items, please use the “Regenerate/reset” function:
https://permalinkmanager.pro/docs/basics/how-to-regenerate-the-custom-permalinks/#1-how-does-the-regenerate-reset-tool-work
Ok, I got that to work, thanks. Now when I am creating a archive page or clicking on the /business/ this does not show all the post with that tag. It does the same for categories. How do I show that?
The free version allows to change only the permalinks of individual posts. If you want to edit the post tag archives as well, you will need the Pro version.