IcedEarth213 Posted September 7, 2011 Share Posted September 7, 2011 What I'm trying to do: For my WP site I'm building I have some custom image headings, so instead of <h1> tags, it would be an image. I was trying to build a wordpress function where it would look and see if the page's title has a corresponding image (PNG), and if so, display it. If not, display the regular <h1> tag. It would probably be best to do page slug instead of title though...not sure..here's what I have: function title_image_check($title) { $image = '/images/' . $title . '.png'; $filename = get_bloginfo('template_directory') . $image; if(file_exists($filename)) { $return = '<span class="img-title"><img src="'.get_bloginfo('template_directory').$image.'" alt="'.$title.'" /></span>' ; } else { $return = '<h1 class="title">' . $title . '</h1>'; } return $return; } add_filter('the_title', 'title_image_check'); It's currently broken, it always returns the 'else' value, even though I have an image named appropriately. Ideas? Link to comment https://forums.phpfreaks.com/topic/246639-wordpress-php-q-getting-a-img-filename-and-doing-ifelse/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.