WordPress Code Snippets

A fresh mix of code snippets and tutorials

Recursively display images via PHP


Here is an easy way to display all images in a directory — including images contained in sub-directories.

Just add the following snippet to your script:

This is a basic example showing how PHP’s glob() function can be used to display any/all images from a directory in recursive fashion. For example, I adapted this technique to auto-display all images from a WordPress /uploads/ directory that had images organized by year, so recursive functionality was required to display the images from each year’s directory.

Show Support

Like our new Facebook Page to show support!