Title: File_Exists Function Won&#039;t Work Inside Header.php
Last modified: August 19, 2016

---

# File_Exists Function Won't Work Inside Header.php

 *  [chaseman](https://wordpress.org/support/users/chaseman/)
 * (@chaseman)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/file_exists-function-wont-work-inside-headerphp/)
 * 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)

 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/file_exists-function-wont-work-inside-headerphp/#post-1998636)
 * Try using the full filepath.
 * Change this:
 *     ```
       $logo = "/images/logo.png";
       ```
   
 * to this:
 *     ```
       $logo = get_stylesheet_directory() . "/images/logo.png";
       ```
   
 *  Thread Starter [chaseman](https://wordpress.org/support/users/chaseman/)
 * (@chaseman)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/file_exists-function-wont-work-inside-headerphp/#post-1998650)
 * Thanks a bunch, that worked!

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.

## Tags

 * [file_exists](https://wordpress.org/support/topic-tag/file_exists/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [chaseman](https://wordpress.org/support/users/chaseman/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/file_exists-function-wont-work-inside-headerphp/#post-1998650)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
