Template Include crashing browser

You have a couple mistakes in your code:

is_archive() does not accept any parameters. If you want to check if this is the archive of a custom post type, use is_post_type_archive( $post_type )

  • Instead of using include( plugin_dir_path( __FILE__ ) . 'my-template.php');, use dirname( __FILE__ ) . 'my-template.php';

  • Single templates has its own filter, single_template, so split your function so that you have your template_include for the archive page separately

Try something like this

add_filter('template_include', function ( $template ) {

    if( is_post_type_archive( 'hhavideo' ) ){
        $template = dirname( __FILE__ ) . '/templates/archive-hhavideo.php';
    }
    return $template;

}, PHP_INT_MAX, 2 );

add_filter( 'single_template', function ($single_template) {

    if ( is_singular( 'hhavideo' ) ) {
        $single_template = dirname( __FILE__ ) . '/templates/single-hhavideo.php';
    }
    return $single_template;

}, PHP_INT_MAX, 2 );

Leave a Comment

tech