Hey guys, I really need some help figuring this out.
I would like to randomly select an image from a folder within my theme. I have a custom function in the functions.php which makes the call and echoes the correct html code.
This is what the function looks like:
$path = "wp-content/themes/white/imgs/header/";
$images = glob($path."*.{jpg,png,gif}", GLOB_BRACE);
shuffle($images);
echo "<img src='".$images[0]."'>";
The problem is that when using permalinks like http://www.example.com/products/something the relative path given in the function won't work. Is there some built in functionality for solving this problem?
I was thinking about sending the current URL when calling the function. And from there figure out how to write the relative path including the number of "../" it takes to get it right.
Anyone?