Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following custom post-type and custom taxonomy setup:

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'system',
            'labels' => array(
                'name' => __( 'Systems' ),
                'singular_name' => __( 'System' )
        'capability_type' => 'post',
        'supports' => array('title','editor','comments'),   
        'public' => true,
        'has_archive' => true,
        'rewrite' => array( 'slug' => 'system' ),

function news_init() {
            'label' => __( 'Product Category' ),
            'sort' => true,
            'hierarchical' => true,
            'args' => array( 'orderby' => 'term_order' ),
            'rewrite' => array( 'slug' => 'product-category' )
add_action( 'init', 'news_init' );

Is it possible to include the custom taxonomy name in the URL?

At present when I goto a custom post the URL looks like this:


How can I make it look like the following?


share|improve this question
add comment

1 Answer

This can be a bit challenging for WordPress, because it wouldn't know whether you are referring to post, page or taxonomy. Nevertheless, rename your taxonomy to something like product_category and try changing the slug in your post type arguments to system/%product_category%, and slug in your taxonomy arguments to just system. WordPress should now handle /system/your-product-category/post-name/

Out of the box WordPress doesn't recognize the permalink structure tag %product_category%, so we need to declare it:

function filter_post_type_permalink($link, $post)
    if ($post->post_type != 'system')
        return $link;

    if ($cats = get_the_terms($post->ID, 'product_category'))
        $link = str_replace('%product_category%', array_pop($cats)->slug, $link);
    return $link;
add_filter('post_type_link', 'filter_post_type_permalink', 10, 2);


  1. This will just grab the first product category for the post ordered by name.
  2. There still may be some 404 errors, if pages, posts etc., have same names.
share|improve this answer
Thanks for the answer. No luck though. I'm still getting the 404 pages for all of the taxonomy pages. I even did the re-save permalinks to flush each time just in case but no luck. –  Rob Oct 24 '12 at 14:16
Make sure use flush_rewrite_rules() to flush out everything. Add it to your hooks when you activate/deactivate your plugin ------------------------------------------ 'register_activation_hook( FILE, array( 'Your_Hook', 'on_activation' ) ); register_deactivation_hook( FILE, array( 'Your_Hook', 'on_deactivation' ) ); register_uninstall_hook( FILE, array( 'Your_Hook', 'on_uninstall' ) );' –  user952851 Mar 7 at 13:29
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.