The is_random_header_image() WordPress PHP function checks if a random header image is in use.
Usage
is_random_header_image( $type );
Custom example:
Input:
is_random_header_image( 'default' );
Output:
true
or false
Parameters
$type
(string, optional): The random pool to use. Possible values include'any'
,'default'
,'uploaded'
. Default:'any'
.
More information
See WordPress Developer Resources: is_random_header_image()
Examples
Check if random header image is in use
This code checks if the random header image is in use and echoes a message accordingly.
if ( is_random_header_image() ) { echo 'Random header image is in use.'; } else { echo 'Random header image is not in use.'; }
Check if random ‘default’ header image is in use
This code checks if the random ‘default’ header image is in use and echoes a message accordingly.
if ( is_random_header_image( 'default' ) ) { echo 'Random default header image is in use.'; } else { echo 'Random default header image is not in use.'; }
Check if random ‘uploaded’ header image is in use
This code checks if the random ‘uploaded’ header image is in use and echoes a message accordingly.
if ( is_random_header_image( 'uploaded' ) ) { echo 'Random uploaded header image is in use.'; } else { echo 'Random uploaded header image is not in use.'; }
Display a message based on the type of random header image
This code checks the type of random header image in use and displays a message accordingly.
$type = 'any'; if ( is_random_header_image( $type ) ) { echo "Random $type header image is in use."; } else { echo "Random $type header image is not in use."; }
Display a message if a specific type of random header image is not in use
This code checks if a specific type of random header image is not in use and displays a message accordingly.
$type = 'uploaded'; if ( ! is_random_header_image( $type ) ) { echo "Random $type header image is not in use."; }