How to test if a custom header image is used in WordPress

- by

You can use a handy function named get_header_image() for this. It will return the image uploaded by a user, or an empty string if a custom header image is not used.

You can base decisions on this query:

if (get_header_image() == '') {
    // if no header image is present, do this
} else {
    // if we have a header image, do something else
}

Note that get_header_image() is not a boolean function, so testing like this won’t work:

if (get_header_image()) {
    // this is not going to work
}

Find more details in the WordPress Codex:



If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.