Richard-B
Member
Posted 1 year ago #
Does anyone know if it is possible to check if the theme has an image header selected in the admin? I have added the new header support (from this tutorial http://www.wpbeginner.com/wp-themes/how-to-enable-custom-header-images-panel-in-wordpress-3-0/)
I thought it might be something like this, apparently its not that simple though :)
<?php if ( header_image ()) { ?>
// do stuff
<img src="<?php header_image(); ?>" alt="" />
<?php } else { ?>
// do something else
<?php } ?>
This works for me:
// output header image & text CSS
if ( !function_exists( 'theme_custom_header_style' ) ) :
function theme_custom_header_style() {
echo '<style type="text/css" media="screen">'."\n";
if( get_header_image() != '' ) echo '#header-image {background-image:url(' . get_header_image() . ');}';
if( get_header_textcolor() == 'blank' ) echo '#header h1,#header h1 a {position:absolute;top:-5000px;left:-5000px;}';
else echo '#header h1,#header h1 a {color:#' . get_header_textcolor() . ';}';
echo "\n</style>\n\n";
}
endif;
Richard-B
Member
Posted 1 year ago #
Esmi thank you so much, with a bit of adjustment that worked great for me too. In the theme i'm working on you can only upload a header image so I changed it to the following.
<?php if (get_header_image() != '') {?>
// yes
<?php } else { ?>
// no
<?php } ?>
Thanks again, I could not have done this without your help!