PHP File_exist() not working - Checking if File Exist in WordPress Theme Directory
I am trying to check if a certain archive file template exists in the WP theme directory. This is my code, I am not sure what I am missing here.
?php
$file_name = '/archive.php';
$base_template_dir = get_template_directory_uri();
$file_uri = $base_template_dir.$file_name;
$file_uri = str_replace('http://', '', $file_uri);
$file_uri = str_replace('https://', '', $file_uri);
$file_uri = str_replace($_SERVER['HTTP_HOST'], '', $file_uri);
if (file_exists($file_uri)) {
echo 'File Found: '.$file_uri;
} else {
echo 'File Not Found: '.$file_uri;
}
?
Topic wp-filesystem plugin-development theme-development Wordpress
Category Web