Custom post type single page uses the right template in preview mode but shows a different template after being posted

I've been developing a Wordpress theme. I've created a custom post type called blog in functions.php.

// Blog Post Type Creation
function te_blog_type() {
    register_post_type("blog",
        array(
            "rewrite" = array("slug" = "blogs"),
            "labels" = array(
                "name" = "Blogs",
                "singular_name" = "Blog",
                "add_new_item" = "Add New Blog",
                "edit_item" = "Edit Blog"
            ),
            "menu-icon" = "dashicons-format-status",
            "public" = true,
            "has_archive" = true, 
            "supports" = array(
                "title", "thumbnail", "editor", "excerpt", "comments"
            ),
            "taxonomies" = array("category", "post_tag", "blog_tag")
        )
    );
}

add_action("init", "te_blog_type");

It's been working fine.

I also created a single-blog.php file as template for each blog post. When I preview the blog post. It's using the right template from single-blog.php. However, when I actually post the blog, it's showing the index.php as the template. What caused this?

Topic previews templates theme-development custom-post-types Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.