file_exists()
lets you check if a file exists on the local server, by passing it a file path. It cannot be used to check for the existence of files via URL, and you’re passing it the result of get_stylesheet_directory_uri()
, which returns the URL (http:// etc.) to the file, not the path.
The proper way, these days, to get the path to a theme file is to use get_theme_file_path()
, like so:
$filecs = get_theme_file_path( 'css/lucilevi.css' );
$filejs = get_theme_file_path( 'js/lucilevi.js' );
if ( file_exists( $filecs ) ) {
// etc.
}
if ( file_exists( $filejs ) ) {
// etc.
}
Just be aware that because $filecs
and $filejs
are file paths, you cannot pass them to wp_enqueue_style()
, wp_enqueue_script()
, you still need to pass URLs to those.