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 want to change my custom post URL. I want to remove "item" from URL.

With the below code and with custom post type url plugin http://wordpress.org/plugins/custom-post-type-permalinks/ my URL is:

Original URL : http://mywebsite/wp/item/america/mayer/

Want to change it to http://mywebsite/wp/america/mayer/

Without using htaccess.

WordPress Code

    function aitDirItemPostType() {

        register_post_type( 'ait-dir-item',
            array(
                'labels' => array(
                    'name'          => 'Items',
                    'singular_name' => 'Item',
                    'add_new'       => 'Add new',
                    'add_new_item'  => 'Add new item',
                    'edit_item'     => 'Edit item',
                    'new_item'      => 'New item',
                    'not_found'     => 'No items found',
                    'not_found_in_trash' => 'No items found in Trash',
                    'menu_name'     => 'Items',
                ),
                'description' => 'Manipulating with items',
                'public' => true,
                'show_in_nav_menus' => true,
                'supports' => array(
                    'title',
                    'thumbnail',
                    'author',
                    'editor',
                    'excerpt',
                    'comments',
                ),
                'show_ui' => true,
                'show_in_menu' => true,
                'menu_icon' => AIT_FRAMEWORK_URL . '/CustomTypes/dir-item/dir-item.png',
                'menu_position' => $GLOBALS['aitThemeCustomTypes']['dir-item'],
                'has_archive' => true,
                'query_var' => 'dir-item',
                'rewrite' => array('slug' => 'item'),
                'capability_type' => 'ait-dir-item',
                'map_meta_cap' => true
            )
        );
        aitDirItemTaxonomies();

        flush_rewrite_rules(false);
    }

add_action( 'init', 'aitDirItemPostType');
share|improve this question
1  
"item" is the basename for your custom post type. You can change it in this line of code 'rewrite' => array('slug' => 'item'), but you can't remove it. If you change it, remember you need to flush the rewrite rules afterwards by visiting the permalinks page in the administrative dashboard. –  epilektric May 15 at 13:12
    
no this is a theme code.and if i will change according to you then url will use air-dir-item in place of item. so another solution please.. –  Sonu May 15 at 13:22

1 Answer 1

You can omit the "base", by adding

rewrite => array(
    slug       => 'item',
    with_front => false,
),

Don't forget to flush your rewrite rules after you changed that. The easiest way to do so it to simply visit the "admin > settings > permalinks" page.

If you need to add that to an already registered post type, then take a look at the internals of register_post_type() and the available hooks and filters in its source Link to GitHub: Make use of the registered_post_type action which comes with two arguments: $post_type and $args.

share|improve this answer
    
sorry with your solution my prob not solved. :( support.ait-themes.com/support/topic/65444 and support.ait-themes.com/support/topic/6329 –  Sonu May 15 at 13:43
    

Your Answer

 
discard

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.