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;
}
?>
$mPath
? I don't see it defined anywhere in your code.$file_uri
variable – However, the code still doesn't work even though i have an archive.php file available in the theme's directory$file_uri
wouldn't work, and I was only telling you that you've used an undefined variable.