file_exists()
通过向本地服务器传递文件路径,可以检查该文件是否存在于本地服务器上。它不能用于通过URL检查文件是否存在,您将通过get_stylesheet_directory_uri()
, 返回文件的URL(http://etc),而不是路径。
现在,获取主题文件路径的正确方法是使用get_theme_file_path()
, 像这样:
$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.
}
要知道,因为
$filecs
和
$filejs
是文件路径,您无法将其传递给
wp_enqueue_style()
,
wp_enqueue_script()
, 您仍然需要将URL传递给这些。