Ethan Jinks O'Sullivan Ethan Jinks O'Sullivan - 2 months ago 6
PHP Question

PHP: Alternative to returning a blank file

In my

blank.php
it currently has following:

<?php
// Blank file...


I am using this file to replace a particular template in my WordPress like so:

add_filter( 'comments_template', blank_file' );
function blank_file() {
return PLUGIN_PATH . '/blank.php';
}


However, instead of creating a blank file to return, is it possible to just return a blank value to get the same results? I tried the following which would make sense to me logically, but it didn't work:

function blank_file() {
$blank = '<?php';
return $blank;
}

Answer

I found a similar question on WordPress Stack Exchange here. However, it looks like the solutions require more coding than what I am currently using which works for me:

add_filter( 'comments_template', 'comments_template', 20, 1 );
 function comments_template() {
    return plugin_dir_path( __FILE__ ) . 'blank.php';
}

Where blank.php has:

<?php
// Blank file...