• Resolved Jean Felipe

    (@jean-felipe)


    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');
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Sajjad Hossain Sagor

    (@sajjad67)

    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 alt="here goes your alt description" src="' . $image_url . '" style="max-height:100px;">'; // Output the image
        }
    }
    add_shortcode('tags_image_archive', 'wpc_elementor_shortcode_2');

    Here is a modified code of yours, previously you were not including alt tag in your img tag. Hope that helps.

    Thread Starter Jean Felipe

    (@jean-felipe)

    Hi,

    Sorry for not being more specific. I would like the image to show its alt tag, as it is added in its media settings in WordPress. Let’s say I’ve added an alt tag for each image for SEO purposes.

    So if the tag is “Dogs”, I have added the word ‘dog’ in the Alt attribute of the image uploaded.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Image alt tag’ is closed to new replies.