If File Exists Post Image, if Not, post title.
-
I’m having one hell of a time working this code out. Basically for pages, instead of posting the_title(), I want it to look for an image with the the_title() name and if it is available in the theme’s dir/images/the_title().png to post the image, and if not, just post the title. Here is what I have:
<?php $image = bloginfo('template_url') . the_title("/images/",".png"); if (file_exists($image)) { echo "you're in good shape"; } else { echo "yolo fool" . $image . "after stuff"; } ?>
first issue is that it echo’s
https://www.mywebsite.com/wp-content/themes/v1/images/Sponsors.png
Which is the exact address of the image, and then it returns:
yolo foolafter stuff
So as you can see, I cannot use this variable to call the image. Any ideas?
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘If File Exists Post Image, if Not, post title.’ is closed to new replies.