Skip to main content
Tweeted twitter.com/#!/StackWordPress/status/489378123205840896
edited title
Link

I want to extend the current themesthemes' single.php to display the meta fields of my CPT

Source Link

I want to extend the current themes single.php to display the meta fields of my CPT

I am developing a plugin, which registers a role, a CPT and some metaboxes. I am now at the point where I included as well a single-mycpt.php into my plugin.

Here's my current issue: I can't simply assume they will be using twentyforteen, so I cannot copy paste that single and extend it to my needs. Is there an established best practice to retrieve and extend the currently used single.php of the currently used theme?

At the moment I register* a copy of the single.php of my current theme, but I would love it to be generally more usable.

*

/* Filter the single_template with our custom function */
function add_mycpt_template( $single ) {
    global $wp_query, $post;

    /* Checks for single template by post type */
    if ($post->post_type == 'mycpt') {
        if(file_exists(dirname( __FILE__ ) . '/templates/single-mycpt.php')) {
            $single_template = dirname( __FILE__ ) . '/templates/single-mycpt.php';
        }
    }
    return $single_template;
}
add_filter('single_template', 'add_rechungs_template');