Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Setting background image to category header WordPress


I want users to be able to set a default image for a category, and have it appear in the header for the category page. So, for example, here:

The gray header area currently shows the category description. I've installed the following plugin:

That lets me set a default image for a category, and I've done so. Now, in theory, the image can be displayed to the front-end by using a shortcode ['header_ads_image'] or using <?php if (function_exists('hmk_taxonomy_image_url')) echo hmk_taxonomy_image_url(); ?> to get the url and put it in any img tag in header or any page template.

I obviously can't do that using CSS, and I'm not sure that, in this theme, I could easily set the class .source-page (the class of the header area) to have a background image that's set via php.

Am I going about this the wrong way? Any recommendations? Thank you!

Answers (1)


timDesain Nanang answers:

Hi Sir, have you tried this:

add_action('wp_head', 'wpq_wp_head');
function wpq_wp_head(){
if (function_exists('hmk_taxonomy_image_url')) {
$hmk_image = esc_url( hmk_taxonomy_image_url() );
if(!empty( $hmk_image ) ){
?><style type="text/css"><?php
echo ".source-page {background: #FAC564 url('".hmk_taxonomy_image_url()."') repeat top !important;} ";

put the code on theme's functions.php

michaelmiller comments:

I did that, and it worked perfectly. Thank you, sir!

timDesain Nanang comments:

You are welcome.