Inside a function I’m doing something like this:
$optional_css_exists = get_template_directory_uri() . "/css/optional.css";
if ( file_exists($optional_css_exists) ) {
wp_enqueue_style('options', get_template_directory_uri() . '/css/optional.css', 'style');
}
But for some reason it’s not being enqueued. When I echo out $optional_css_exists, I get the correct path of the file.
If I remove the if statement, the file is enqueued.
Why isn’t the file being enqueued when it exists and the path is correct?
URL path can’t be passed to
file_exists
PHP: file_exists – Manual
Use
get_template_directory()
orget_stylesheet_directory()
instead:as that returns server path