I’m working on a custom theme framework for educational purposes.
I basically have a header.php in a child theme that i want to make smarter. I’d like to only include a stylesheet if the file exist. Getting 404 errors is not cool or efficient.
Are there native php or wordpress functions to check if a wordpress file exist.
Basically…
I want to output
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/css/<?php echo get_stylesheet() ?>.css" type="text/css" media="screen" />
Only If the stylesheet with the same name as the folder containing the child theme exist.
Any ideas would be awesome 🙂
There’s a lot of ways you could go with this. I might enqueue the style in your theme’s functions.php dependent on a
file_exists()
check.Here’s the relavent core source.