How to add images into each category?

hello,

i was trying to figure out how i could add a banner to my category pages. I want to display an image on top of the category chosen. for example on my weight loss category, i want to display an image of a person measuring their stomach.

thank you in advance.

Hi Awilla,

Thanks for reaching out.

Please check this related threadhttps://theme.co/apex/forum/t/text-on-top-of-categorys-archive/33877/14.

You’ll have to implement the same code and modify it to display an image instead just text or block. Example, add this code to child theme’s functions.php

function category_image_banner() { 

 if ( is_category( 743) ) : ?>

<img src="http://example.com/image.jpg">

<?php endif; 


}
add_action('x_after_masthead_end','category_image_banner', 30);

Where 743 is category ID, please check this https://theme.co/apex/forum/t/setup-how-to-locate-category-ids/60. And if you wish to implement more banner specific to categories then just duplicate the if-condition block. Example,

function category_image_banner() { 

 if ( is_category( 743) ) : ?>

<img src="http://example.com/image.jpg">

<?php endif; 

 if ( is_category( 760) ) : ?>

<img src="http://example.com/image2.jpg">

<?php endif; 

 if ( is_category( 8347 ) || is_category( 8900 ) ) : /* this means same banner for two categories */ ?>

<img src="http://example.com/image3.jpg">

<?php endif; 


}
add_action('x_after_masthead_end','category_image_banner', 30);

Hope this helps.

Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.