• flagsuser

    (@flagsuser)


    I want to show the alt text as set in admin panel for an image specially logo but my site is showing some other text for alt and not what I have set in admin panel. I am using the following code for showing user defined alt text but its not working for logo though it works for rest of the images in the website.

    Here is the code I’m using on other pages for showing alt text:

    $thumb_id = get_post_thumbnail_id(get_the_ID());
    $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);

    And in image I am doing like this:
    <img src="img-source-value" alt="<?php echo $alt; ?>" />

    This same code works for other images but not on site logo image. Can please someone tell me what’s wrong in this code for logo image? Thanks in advance.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Site logo or site header image? The logo is the site icon that shows up in tabs and shortcuts. Header image is often a business logo displayed at the top of the page. The image doesn’t necessarily have a post associated with it, so get_post_thumbnail_id() is not an appropriate function. Not all images have a saved alt text as well. If one exists, the header image ID can be had with get_theme_mod( 'header_image_data' )->attachment_id. Then get the alt text from postmeta if it exists under the key “_wp_attachment_image_alt”.

Viewing 1 replies (of 1 total)
  • The topic ‘Show alt as sent in admin panel’ is closed to new replies.