WordPress slug without custom post type slug WordPress slug without custom post type slug wordpress wordpress

WordPress slug without custom post type slug


You must register your post type movie in init.

register_post_type('movie', $args);

To replace the movie from post link use the below code.

function remove_my_post_type($post_link, $post, $leavename) {    if ($post->post_type != 'movie' || $post->post_status != 'publish') {        return $post_link;    }    $post_link = str_replace('/' . $post->post_type . '/', '/', $post_link);    return $post_link;}add_filter('post_type_link', 'remove_my_post_type', 10, 3);

After that you can set your post type shold be like a default post or page.

function set_my_post($query) {    if(isset($query->query['post_type'])){        return;    }    if (!empty($query->query['name'])) {        $query->set('post_type', array('post', 'movie', 'page'));    }}add_action('pre_get_posts', 'set_my_post');


I do not think there is straight forward solution this. If you need this so badly you can use Custom Rewrite For Post Slug


Have you tried:

'with_front' => bool Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true

https://codex.wordpress.org/Function_Reference/register_post_type