WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to check if a file exist in my plugin dir:

if (fileexists) {

However, if in place of fileexists I use file_exists(WP_PLUGIN_DIR . "/myplugin/myfile.ext") it returns always true, whereas if I use file_exists(plugins_url( "myfile.ext", __FILE__ )) it returns always false, irrespective of the argument I use is a file that exists or not.

I do not know if it is relevant to specify that I'm working in a locale environment. WP_PLUGIN_DIR returns C:\Users\MyName\Documents\webserver\www\wordpress/wp-content/plugins/myplugin/myfile.ext (and I see some slashes and some backslashes).

share|improve this question
up vote 1 down vote accepted


if( file_exists(plugin_dir_path(__FILE__) . 'myfile.ext') ) {}

instead of

if( file_exists( plugins_url( "myfile.ext", __FILE__ ) ) ) {}

See plugin_dir_path in the Codex.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.