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');

Well, you could hook into the the_content filter, asking if it was a single custom post type and then replace the output with something you like.

Something like this:

function content_my_cpt_filter( $content ) {
    if (is_singular() && (get_post_type() == 'my_cpt')) {
        $returnage = $content;
        $returnage .= 'Other Stuff that needs to be displayed on the single CPT';
        return $returnage;

    return $content;

add_filter( 'the_content', 'content_my_cpt_filter', 100 );

Happy Coding,


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.