From the documentation on bloginfo
:
This always prints a result to the browser. If you need the values for use in PHP, use
get_bloginfo()
.
And checking the docs on get_bloginfo()
, you'll see that's better to use get_stylesheet_directory_uri()
, so your code would be
$dirpath = get_stylesheet_directory_uri()."/imagefolder";
$folder = opendir($dirpath);