questions

Not getting the content of template made in plugin

Rate this post

I have created a template in my plugin with the help of this code

function ldc_add_thanku_page_template ($templates) {
    $templates['thanku.php'] = 'Thanku Template';
    return $templates;
}
function ldc_redirect_thanku_page_template ($template) {
    if ('thanku.php' == basename ($template))
        $template = PLUGIN_PATH .'templates/public/thanku.php';
    return $template;
}

But when i am assigning this template to any page I am not getting the content inside it. For now i have added a very simple code, can anyone please help me with this.

<?php  
/* Template Name: Thanku Template */
 echo "<h1>Hello</h1>"; 
?>

 

✔️Solution:

Your Code will not work on the latest WordPress version, This code will work below 4.7

Try This

function ldc_add_thanku_page_template ($templates) {
    $templates['thanku.php'] = 'Thanku Template';
    return $templates;
}
function ldc_redirect_thanku_page_template ($template) {
    $post = get_post();
    $page_template = get_post_meta( $post->ID, '_wp_page_template', true );
    if ('thanku.php' == basename ($page_template))
       $template = WP_PLUGIN_DIR .'/mypluginname/thanku.php';
    return $template;
}

Leave a Reply

Your email address will not be published.

Back to top button