Remove taxonomy-base from URL in WordPress
I have a little problem with removing the taxonomy base from the URL in Wordpress. I tried different approaches but none worked.
register_taxonomy('project_category','projects',array(
'labels' => $labels,
'show_ui' => true,
'rewrite' => array开发者_StackOverflow社区(
'slug' => 'project-category',
'with_front' => false,
'hierarchical' => true),
'hierarchical' => true)
);
I currently see the URL like this : http://mysite.com/project-category/project1 and i want it to be like this: http://mysite.com/project1.
I tried to rewrite the slug to '' instead 'project-category' but that messed with all my othr pages, redirecting to a 404 page.
Heres how I've manage to get my url to rewirte to a spcific url.
add_action('init', 'portfolio_register');
function portfolio_register() {
$args = array(
'label' => __('Portfolio'),
'singular_label' => __('Project'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail')
);
register_post_type( 'portfolio' , $args );
}
register_taxonomy(
"project-type",
array("portfolio"),
array("hierarchical" => true,
"label" => "Project Types",
"singular_label" => "Project Type",
"rewrite" => true
));
Also check out some tutorials and sometimes you can grab bits& pieces from theme.
- Wordpress custom post types
- Rock solid wordpress 3.0 post types
- Custom post type tools & advice
Try this
Just drop it into wp-content/plugins
and activate. It is in the process of being added to the WP repository.
use this plugin https://github.com/alexvornoffice/remove-taxonomy-base-slug, what this does? It removes base slug from all taxonomies, and check if the slug is the same as post type slug, and rewrites the rules in the such way so the taxonomy slug will have a better priority over post type slug.
精彩评论