Why custom post redirecting to index page?

i am new learner and trying to build a wordpress themei need your help in theme building ,my problem is that, i created a custom post type name is events
and also created a single-events.php template inside my theme so that only events post can be display but when i clicked on permalink of it’s post then it does not redirect to single-events.php, it redirect to index page ,can please anybody give me solution with example.

/custom post code is/

add_action (‘init’, ‘register_events_posttype’);
function register_events_posttype(){
$labels = array();

$args = array(
‘label’ => ‘events’,
‘labels’ => $labels,
‘publicly_queryable’ => true,
‘rewrite’ => array(‘slug’ => ‘events’),
‘show_in_menu’ => true,
‘show_ui’ => true,
‘show_in_nav_menus’ => true,
‘show_in_rest’ => true,
‘menu_position’ => 2,
‘public’ => true,
‘has_archive’ => true,
‘menu_icon’ => ‘dashicons-calendar-alt’,
‘supports’ => array(‘title’,’editor’,’thumbnail’, ‘excerpt’,’custom-fields’,’thumbnail’, ‘archives’,),
‘taxonomies’ => array(‘category’, ‘post_tag’),
‘rewrite’ => array(‘slug’ => ‘events’,’with_front’ => false)
register_post_type(‘events’, $args);

/and single-events.php code is/



events post
<?php echo get_the_title();?>

can you please solve it ?

Read more here:: Why custom post redirecting to index page?

Leave a Reply

Your email address will not be published. Required fields are marked *