Last active
January 25, 2023 14:51
-
-
Save woogists/fceab984722fdb964eb5c567e5d4905c to your computer and use it in GitHub Desktop.
[Theming] Display category image on category archive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Display category image on category archive | |
*/ | |
add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 ); | |
function woocommerce_category_image() { | |
if ( is_product_category() ){ | |
global $wp_query; | |
$cat = $wp_query->get_queried_object(); | |
$thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true ); | |
$image = wp_get_attachment_url( $thumbnail_id ); | |
if ( $image ) { | |
echo '<img src="' . $image . '" alt="' . $cat->name . '" />'; | |
} | |
} | |
} |
Hi, is possible to add a link to the image?
I need to have an image with external link in some specific category page for legal reason.
Thanks in advance
Hi,
Where does this code go? I have tried the functions.php file with no luck.
I also uploaded the file itself but that didn't work either. If it works that way where should I upload it to?
Thank you :-)
Do I add wc-display-category-image-archive.php to includes?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I have the opposite requirement: my template displays the categories images and I don't want them. How and in which file can I modify that?
Thanks.