Here i read that if i create a custom post type, WordPress will look to its specific template first, then it falls back to single.php.

I registered a custom post type (i’ll show the taxonomy as well), which is properly shown in admin; i can create them well and i’ve been able to add them to the list of posts in blog’s main page.
However, when i try to visit its page, i’m not getting a 404 error, but title is not shown in head section and it uses the index.php template, although i have a single.php which is working with common posts and i’d like to use. My new type (in functions.php)

function mytheme_customtypes () {
    $post_args = array(
        'label' => _('Blog Post'),
        'description' => _('Site's blog posts'),
        'show_ui' => true,
        'show_in_nav_menus' => true,
        'taxonomies' => array('blog_posts'),
        'supports' => array('title', 'editor', 'comments', 'trackbacks', 'thumbnail'),
        'capability_type' => 'post',
        'rewrite' => array('slug' => 'blog', 'has_archive' => 'blog_posts', 'with_front' => false)
    );

    $tax_args = array(
        'label' => 'Blog posts',
        'description' => _('Raccolta dei post per il blog'),
        'show_ui' => true,
        'show_in_nav_menus' => true,
        'rewrite' => array('slug' => 'blogs',  'with_front' => false),
        'hierarchical' => true
    );

    register_post_type('blog_post', $post_args);

    register_taxonomy('blog_posts', 'blog_post', $tax_args);
}
add_action('init', 'mytheme_customtypes');

Trying to create a new template name single-blog_post.php had no effect. Any help is appreciated

Read more here: Custom post type is using the index.php template


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: