0

I have created a plugin which displays testimonials and when each is clicked it redirects to the single page. So I wrote this code which is directing properly the single view to the one I created but only in that page its giving me an undefined get_header(); and get_footer()

//controller
class Jetty_Testimonials_Display_Single_Template{

  public function init(){

    //add_filter( 'template_include', array($this, 'jetty_get_template_hierarchy'));
    add_filter( 'template_include', array($this, 'jetty_template_chooser'), 99);

  }

  public function jetty_template_chooser( $template ) {

      $post_id = get_the_ID();

    if ( get_post_type( $post_id ) != 'jetty-testimonials' ) {
        return $template;
    }

    if ( is_single()  ) {
            return plugin_dir_url( __FILE__ ) . '../templates/single-jetty-testimonial.php';
    }

  }
<?php
/**
 *@uses output the single testimonial details
 * @package jetty-testimonials
 * @version 1.0.0
 */

get_header(); ?>
            <?php
            global $post_id;

            print_r($post_id);
            /* Start the Loop
            while ( have_posts() ) : the_post();

                get_template_part( 'template-parts/post/content', get_post_format() );

            endwhile; // End of the loop.*/
            ?>

<?php get_footer();?>

1 Answer 1

0

You can check below code : change Page slug "gym-dashboard" as per your requirement.

<?php
function rt_include_gym_dashboard_page_template( $template ) {
    if ( is_page( 'gym-dashboard' )  ) {
            return plugin_dir_path( __FILE__ ) . 'templates/content-gym-dashboard.php';
    }
    return $template;
}
add_filter( 'template_include', 'rt_include_gym_dashboard_page_template', 99 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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