Custom Post Type in Permalink Structure

I'm looking for the best way to add a taxonomy slug into the permalink structure.

For example, for example, for a "Format" taxonomy with choices Bio, Photos, Videos:

Permalink Structure: /%category%/%format%/%postname%/
Category: John Travolota
Format: Bio
Post without a "Format" taxonomy chosen:

This plugin seems to target this issue, however any post without a "Format" chosen results in a 404 error.

Thanks in advanced!

  • Kimberly
    • Champion of Loops


    Hi and Thanks for using WPMUdev forums!

    It seems that error is the one that makes the plugin you reference hard to use. Seems no-one can get it to work since the latest WP updates.
    That's a link to the last supported thread for that plugin.

    Here is some great info about adding custom taxonomies to your permalink structure as well as translating them properly (this is what commonly causes the 404 error)

    Let me know if this helps :slight_smile:


  • pgt
    • Flash Drive

    Hi Kimberly,

    Thanks for the help. I've been able to achieve the permalink structure I am looking for using the following code:

    add_filter('post_link', 'brand_permalink', 10, 3);
    add_filter('post_type_link', 'brand_permalink', 10, 3);

    function brand_permalink($permalink, $post_id, $leavename) {
    if (strpos($permalink, '%brand%') === FALSE) return $permalink;

    // Get post
    $post = get_post($post_id);
    if (!$post) return $permalink;

    // Get taxonomy terms
    $terms = wp_get_object_terms($post->ID, 'brand');
    if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) {

    $taxonomy_slug = $terms[0]->slug;
    return str_replace('%brand%', $taxonomy_slug, $permalink);
    else {
    $taxonomy_slug = '';
    $new_permalink = str_replace('/%brand%', $taxonomy_slug, $permalink);
    return $new_permalink;



    If I go to a post with the taxonomy "Label" set, it works fine. However, whenever I click on a post that doesn't have a "Label" taxonomy set, the permalink structure is okay, but it directs to a Category page for the post rather than the actual Post.

    My current permalink structure: %category%/%brand%/%postname%/

    Looking to achieve: , where Shoes is the Category, and Nike is the Brand.

    If there is no "Brand" selected:

    Again, the code above gives the posts the right structure, yet whenever I click on a post that doesn't have a "brand" selected, the page it shows is just the category page rather than post.

    I'm going to play around with it more but thought I'd post to see if anyone had suggestions.

    Thanks again so much for the links/help!

  • pgt
    • Flash Drive

    I'm sorry, in my comment/example above, when I referenced "Label" I meant "Brand". **

    Also, it seems this plugin would assist the functionality of what I'm looking to achieve, although I think each structure in the examples he shows is prefixed with a static word, which in my case is not what I'm looking for. Still wanted to post as it could be food-for-thought for the next CustomPress update:

    I really appreciate the help thus far and hope someone may have suggestions. Losing sleep over this; the needed permalink structure is vital in my case for SEO reasons and I'm unable to launch until I can figure this out :disappointed:

    Thanks again!


  • aecnu
    • WP Unicorn

    Greetings pgt,

    Thank you for all of your feedback, it is greatly appreciated.

    I am going to see if I can get the lead developer in here with his invaluable input plus add this ticket to the feature requests so that possibly this may become available in Custom Press as a future option.

    Though this may take longer then a normal ticket, I will see if I can get developer input asap.

    Cheers, Joe

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.