pran
pran

Reputation: 19

file_exists(...) not working in wordpress

Trying to use file_exists() function in wordpress but unable to get expected result.

if(file_exists(WP_PLUGIN_URL.'/sinetiks-schools/images/t_1.jpg')){
        echo "ok";
    } else {
        echo "not";
    }

Upvotes: 0

Views: 738

Answers (2)

Muhammad Azam
Muhammad Azam

Reputation: 328

Try to use this one . i hope your problem will be solved

    $image = get_template_directory() . "/images/" . get_the_title() . ".png";
$image2 = get_template_directory_uri() . "/images/" . get_the_title() . ".png";

if (file_exists($image)) 
{
        echo "<img src=" . $image2 . ">";
} 
else
 {
        echo the_title("<h1 class='title'>","</h1>");
 }

Upvotes: 1

Touqeer Shafi
Touqeer Shafi

Reputation: 5264

You should try:

if(file_exists(plugin_dir_path( __FILE__ ).'/sinetiks-schools/images/t_1.jpg')){

}

Make sure you are getting correct path from plugin_dir_path( __FILE__ )

you can find more information on plugin_dir_path function here

Upvotes: 0

Related Questions