Title: conditional permalink
Last modified: May 7, 2021

---

# conditional permalink

 *  Resolved [almeidafelipe](https://wordpress.org/support/users/almeidafelipe/)
 * (@almeidafelipe)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/conditional-permalink-2/)
 * Hello, i have a structure that works like this:
 * mydomain.com/custom-taxonomy-1/category/post-name
 * But I have 3 taxonomy groups:
 * . custom-taxonomy-1
    . custom-taxonomy-2 . Category
 * I would like to know if it is possible to have a different structure if I choose
   a particular item from custom-taxonomy-1. For example:
 * If I choose any item from custom-taxonomy-1 the structure will be normal:
 * mydomain.com/custom-taxonomy-1/category/post-name
 * But if i choose a SPECIFIC item from custom-taxonomy-1 the structure will be 
   different:
 * mydomain.com/custom-taxonomy-1/custom-taxonomy-2/post-name
 * I have the alternative of creating a custom post and defining this alternative
   structure for him, but I didn’t want to do that because the posts have the same
   architecture. It was just to have a different permalink structure.

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Maciej Bis](https://wordpress.org/support/users/mbis/)
 * (@mbis)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14413088)
 * Hi [@almeidafelipe](https://wordpress.org/support/users/almeidafelipe/),
 * To make the post permastructures conditional you will need a custom snippet.
 *     ```
       function pm_conditional_permastructure($permastructure, $post) {
       	// Do not change native permalinks or differnt post types
       	if($native_uri || $post->post_type != 'post') { return $default_uri; }
   
       	// A. Any term in 'custom-taxonomy-1' taxonomy
       	if(has_term('', 'custom-taxonomy-1')) {
       		$permastructure =  "%custom-taxonomy-1%/%category%/%postname%";
       	}
       	// B. Specific term in 'custom-taxonomy-1' taxonomy
       	else if(has_term('specific-term', 'custom-taxonomy-1')) {
       		$permastructure =  "%custom-taxonomy-1%/%custom-taxonomy-2%/%postname%";
       	}
   
       	return trim($permastructure, "/");
       }
       add_filter('permalink_manager_filter_permastructure', 'pm_conditional_permastructure', 10, 2);
       ```
   
 *  Thread Starter [almeidafelipe](https://wordpress.org/support/users/almeidafelipe/)
 * (@almeidafelipe)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14413123)
 * Amazing! In this case where there is ‘specific-term’ should i replace it with
   the “custom-taxonomy-1 item slug”?
 * You are a genius!
 *  Plugin Author [Maciej Bis](https://wordpress.org/support/users/mbis/)
 * (@mbis)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14413132)
 * Yes, indeed 🙂
 *  Plugin Author [Maciej Bis](https://wordpress.org/support/users/mbis/)
 * (@mbis)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14415302)
 * Hi [@almeidafelipe](https://wordpress.org/support/users/almeidafelipe/),
 * The version of snippet that I sent you includes a tiny error. Here is the correct
   version:
 *     ```
       function pm_conditional_permastructure($permastructure, $post) {
       	// Do not change native permalinks or differnt post types
       	if($native_uri || $post->post_type != 'post') { return $permastructure; }
   
       	// A. Any term in 'custom-taxonomy-1' taxonomy
       	if(has_term('', 'custom-taxonomy-1')) {
       		$permastructure =  "%custom-taxonomy-1%/%category%/%postname%";
       	}
       	// B. Specific term in 'custom-taxonomy-1' taxonomy
       	else if(has_term('specific-term', 'custom-taxonomy-1')) {
       		$permastructure =  "%custom-taxonomy-1%/%custom-taxonomy-2%/%postname%";
       	}
   
       	return trim($permastructure, "/");
       }
       add_filter('permalink_manager_filter_permastructure', 'pm_conditional_permastructure', 10, 2);
       ```
   
 *  Thread Starter [almeidafelipe](https://wordpress.org/support/users/almeidafelipe/)
 * (@almeidafelipe)
 * [5 years ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14430231)
 * Wooow! Great!
 * I am afraid to use this code and in the future the plugin or wordpress will change
   and the code will stop working.
 * In this case you will make a correction of the plugin but what about the code?
   Will it stop working in the plugin and everything will be messy? Excuse me for
   the question, but i was a little scared now.
 * What do you think?
 *  Plugin Author [Maciej Bis](https://wordpress.org/support/users/mbis/)
 * (@mbis)
 * [5 years ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14430303)
 * The snippet I sent will work only if my plugin is activated and would filter 
   only the default permalink format. It will not break your website for sure 🙂
 * WordPress generates the permalinks dynamically (they are not saved in the database)–
   my plugin stores all the custom permalinks statically in the database.
 * Whenever you publish new post, my plugin will use the existing permalink structure
   to generate and save the particular permalink. It means that even if you remove
   this snippet (or if it will no longer work for any reason), the permalinks saved
   prior to this moment will remain unaffected. That is because my plugin have already
   saved them.
 * Of course you can manually change each of them using included URI editor at any
   moment:
    [https://permalinkmanager.pro/docs/basics/manually-edit-wordpress-custom-permalinks/](https://permalinkmanager.pro/docs/basics/manually-edit-wordpress-custom-permalinks/)
 * The other important thing is that if you would like to restore the original/native
   permalink settings all you need to do is to simply deactivate my plugin.
 *  Thread Starter [almeidafelipe](https://wordpress.org/support/users/almeidafelipe/)
 * (@almeidafelipe)
 * [5 years ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14430408)
 * Many thanks for the reply. One last question:
 * I’m asking these things because i’m setting up a columnist area on my blog. But
   i need a different permalink structure for these columnist posts. Do you think
   that it is better to use this snippet that you provided (which changes the functioning
   of your plugin) or just create a custom post and use your plugin’s custom posts
   native permalink system?
    -  This reply was modified 5 years ago by [almeidafelipe](https://wordpress.org/support/users/almeidafelipe/).
 *  Plugin Author [Maciej Bis](https://wordpress.org/support/users/mbis/)
 * (@mbis)
 * [5 years ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14430695)
 * Hi [@almeidafelipe](https://wordpress.org/support/users/almeidafelipe/),
 * I think that the most convenient way would be to register a new custom post type.
 *  Thread Starter [almeidafelipe](https://wordpress.org/support/users/almeidafelipe/)
 * (@almeidafelipe)
 * [5 years ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14430708)
 * Great. Thank you again.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘conditional permalink’ is closed to new replies.

 * ![](https://ps.w.org/permalink-manager/assets/icon.svg?rev=2625166)
 * [Permalink Manager Lite](https://wordpress.org/plugins/permalink-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/permalink-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/permalink-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/permalink-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/permalink-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/permalink-manager/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [almeidafelipe](https://wordpress.org/support/users/almeidafelipe/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/conditional-permalink-2/#post-14430708)
 * Status: resolved