• Resolved Marcel

    (@marceljm)


    Hello,

    It seems WooCommerce always uses the category name as the alt text for the category image, ignoring the attachment details.

    function woocommerce_subcategory_thumbnail( $category ) {
    ...
        echo '<img src="' . esc_url( $image ) . '" alt="' . esc_attr( $category->name ) . '" ...
    ...

    Is there any hook that would allow me to change it? Otherwise, can you adjust the plugin to use the category name only when the alt is not defined?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support omarfpg a11n

    (@omarfpg)

    Hi @marceljm,

    We appreciate your suggestions and are always looking for ways to improve our products and services, and input from users like you is invaluable.

    We have a website where you can submit feature requests and upvote the ones other people submitted and you like. You can check that out?here.

    In the meantime, I think this should work for you: https://www.w3docs.com/snippets/php/how-to-display-woocommerce-category-image.html.

    Please let us know if there’s anything else we can do to help or if you have further questions.

    Have a wonderful day!
    -OP

    Thread Starter Marcel

    (@marceljm)

    The woocommerce_subcategory_thumbnail didn’t work for me, but I found a workaround, @omarfpg, that uses woocommerce_before_subcategory_title:

    function custom_category_image_alt($category) {
        $thumbnail_id = get_woocommerce_term_meta($category->term_id, 'thumbnail_id', true);
        $image_attributes = wp_get_attachment_image_src($thumbnail_id, 'full');
        if ($image_attributes) {
            $alt_text = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
            if (empty($alt_text)) {
                $alt_text = $category->name;
            }
            echo '<img src="' . esc_url($image_attributes[0]) . '" alt="' . esc_attr($alt_text) . '" width="' . esc_attr($image_attributes[1]) . '" height="' . esc_attr($image_attributes[2]) . '" />';
        }
    }
    remove_action('woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10);
    add_action('woocommerce_before_subcategory_title', 'custom_category_image_alt', 10);
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @marceljm

    I’m glad you were able to find a solution to your inquiry here and thanks for sharing it with the community too! ??

    Should you have further inquiries, kindly create a new topic here.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘alt attribute can’t be changed for category images’ is closed to new replies.