I have searched for solutions but unable find exact answer therefore I'm asking this. If this question is already answered please comment with links.
My problem is, I want to create a plugin with custom post and custom template for that single custom post but I want the permalink should be "http://example.com/post-title" instead of "http://example.com/custom-post-type/post-title" and I don't want to ask user to change their permalink to make this work.
I have use rewrite rules like this
'rewrite' => array('slug'=>'/', 'with_front' => true)
and for template
function get_cpt_template($single_template) {
global $post;
if ($post->post_type == 'cpt') {
$single_template = dirname( __FILE__ ) . '/inc/cpt_template.php';
}
return $single_template;
}
add_filter( 'single_template', 'get_cpt_template' );
This doesn't work and it shows 404 page. But if I changed the 'rewrite' => array('slug'=>'cpt')
then only it works.