Have you ever tried to use the glob() function in your WordPress theme? I have and I'm trying to use it to load a bunch of .css files in my themes folder... Now, let's view the code:
<?php $stylesheets = glob('*.css'); ?> <?php foreach($stylesheets as $stylesheet) : ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/<?php echo $stylesheet; ?>" type="text/css" media="screen" /> <?php endforeach; ?>
If you don't know PHP you probably can't help. But the glob() function is supposed to get all files ending in .css (in this case) in the CURRENT directory.
- That is the directory in which the file in which you placed the code exists. I put the code in the header.php file and hence that is the current directory.
Now, this doesn't work and the reason why is because the glob() function seems not to be searching the current directory but instead is searching the WP core directory, that is with all the WP core files beginning with 'wp-'
But there are no .css files in the core directory and hence the code won't work. Change it to search for .php files like so...
<?php $stylesheets = glob("*.php"); ?> <?php foreach($stylesheets as $stylesheet) : ?> <?php print_r($stylesheet); ?> <link rel="stylesheet" href="/<?php echo $stylesheet; ?>" type="text/css" media="screen" /> <?php endforeach; ?>
And what you get out (if you view page source) is a list of all the WordPress core files AND the links to these files! Surely this is a potential security problem?
I do not understand in any way why the glob() function is searching through the WP root directory, it SHOULD search the theme folder if it's placed in a theme file.
As a note, the code does work if you specify the theme directory link in the arguments like so...
glob("wp-content/themes/mytheme/*.css") and it also works if you put it in its own .php file in the theme directory but this shouldn't have to be done.
Any and all input is appreciated, if there's something I appear to be missing please do tell me because this is rather confusing problem I have encountered, thankyou.