• I’m building a template, and I want a simple if statement to check if the user has added a graphic logo or not, if he doesn’t have added a logo, then the header of the theme should simply display the blog name in normal text in place of the graphic logo.

    Here’s the if statement:

    <?php 
    
    	$logo = "/images/logo.png";
    
    	if (file_exists($logo)) { ?>
    
    		<li><a href="<?php bloginfo('url'); ?>"><img src="<?php bloginfo ('template_directory'); ?>/images/logo.png" alt="<?php bloginfo('description'); ?>" /></a></li>
    
    	<?php } else { ?>
    
    		<li id='blog_name'><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?><font>*</font></a></li>
    
    	<?php } ?>

    The above code won’t work, it will return false every time, which means no file there even if there is one.

    When I add this php file into my themes folder:

    <?php 
    
    $logo = "images/logo.png";
    
    if (file_exists($logo)) {
    
    echo "works"; 
    
    }
    
    ?>

    Then it WILL work, so I’m guessing it must be wordpress specific, that this function is not working inside the header.php file, and I’m wondering what the reason is, and how I can make it work?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘File_Exists Function Won't Work Inside Header.php’ is closed to new replies.