Image alt tag | WordPress.org

[ad_1]

Hello, I’m trying to include the alt attribute in the<img> tags. I’m using the get_taxonomy_image function to fetch the image, but it doesn’t return the alt attribute with the tag. Can anyone show me how I might modify my code to include the alt tag for images? Here’s what I’m currently doing:

function wpc_elementor_shortcode_2($atts) {
    if (!is_tag()) {
        return; // Only run this in tag archives
    }

    $tag_id = get_queried_object()->term_id; // Get the current tag ID
    $image_url = get_taxonomy_image($tag_id); // This function is supposed to fetch the image URL

    if ($image_url) {
        echo '<img src="' . $image_url . '" style="max-height:100px;">'; // Output the image
    }
}
add_shortcode('tags_image_archive', 'wpc_elementor_shortcode_2');

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer