是的,您可以在创建自定义帖子类型时使用rewrite参数:
register_post_type( \'example_type\',
array(
\'labels\' => array(
\'name\' => "Example-Type",
\'singular_name\' => "example-type"
),
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'the-url-you-want\',
)
);
}
您需要重置永久链接才能使其生效。
编辑:
function custom_post_link( $post_link, $id = 0 ){
$post = get_post($id);
if ( is_object( $post ) ){
$terms = wp_get_object_terms( $post->ID, \'category\' );
if( $terms ){
return str_replace( \'%category%\' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( \'post_type_link\', \'custom_post_link\', 1, 3 );