template hierarchy - Custom post type showing index.php

admin2025-06-04  1

I am creating a theme and I have created a new Custom Post Type (CPT) called 'Custom Plugins'. I am trying to get this CPT to use its own template. I have created a single-custom-plugin.php - it doesn't use that. I have created single.php (still early stages with this theme I'm building it to help me learn more) - it doesn't use that either, it uses index.php again.

I'm not sure why this isn't working - I have been referring to the WordPress Developer site for help with structuring, in particular this link and the below image.

I would share the code for the pages, but I don't feel it is relevant as both single.php and single-custom-plugin.php have been temporarily setup as empty files with a single line comment stating the filename. Here is the code for my CPT (again, super basic - maybe I did something wrong here?):

function bravo_plugin_posttype() {
    register_post_type('custom-plugins', array(
        'labels' => array(
            'name' => __('Custom Plugins'),
            'singular' => __('Custom Plugin')
        ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array(
            'slug' => 'custom-plugins'
        )
    ));
}

add_action('init', 'bravo_plugin_posttype');
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749041600a315859.html

最新回复(0)