if file_exists not working with wp_enqueue_style

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.

Read More

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?

Related posts

1 comment

  1. URL path can’t be passed to file_exists

    PHP: file_exists – Manual

    Use get_template_directory() or get_stylesheet_directory() instead:

    if(file_exists(get_template_directory()./path/file.css'))
    

    as that returns server path

Comments are closed.