简体   繁体   中英

Remove slug from custom post type

This has been asked many times but each solution I've tried doesn't work for me - I'm trying to remove the slug of a custom post type. I've tried setting

 'with_front' => false,

but this also doesn't work for me. With this suggestion , it removes the slug in the permalink within the admin area (in my case 'locations') but then visiting the new link I get a 404. I've tried flushing permalinks and this doesn't help. However, I can still access the post by visiting /locations/post-name.

How can I solve this? Thanks in advance.

Try following code

function remove_custom_post_type_slug( $post_link, $post, $leavename ) {

    $post_link = str_replace( '/locations/', '/', $post_link );

    return $post_link;
}
add_filter( 'post_type_link', 'remove_custom_post_type_slug', 10, 3 );

See Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM