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

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:

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

Find more details in the WordPress Codex:

  • http://codex.wordpress.org/Function_Reference/get_header_image

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.

Add your voice!