• Resolved Okoth1

    (@okoth1)


    Hi,

    I’d like to have alt and title attributes with the thumbnails. How can I get them?

    Thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter Okoth1

    (@okoth1)

    Any update on this?

    Plugin Support Michael Nelson

    (@mnelson4)

    Hi @okoth1, sorry for the delay! It’ll sound trite but I was under the weather etc etc.
    When you’re using YARPP’s “Thumbnails” theme, “title” attributes are automatically added to the <a> tag that wraps the <img> tag, and it’s taken from the post’s name.
    The “alt” tag is added to the <img> tag, and it’s taken from the media’s “Alternative Text” field.

    To make it clearer, here’s the HTML generated from YARPP using the Thumbnails theme for one of the related entries:

    <a class="yarpp-thumbnail" rel="norewrite" href="https://yarpp.test/2020/07/17/at-lacinia-massa/" title="at lacinia massa">
    <img src="https://yarpp.test/wp-content/uploads/2020/07/worksofast-120x120.gif" class="attachment-yarpp-thumbnail size-yarpp-thumbnail wp-post-image" alt="HEre is the alternative text, thank you." loading="lazy" data-pin-nopin="true" srcset="https://yarpp.test/wp-content/uploads/2020/07/worksofast-120x120.gif 120w, https://yarpp.test/wp-content/uploads/2020/07/worksofast-150x150.gif 150w" sizes="(max-width: 120px) 100vw, 120px" width="120" height="120">
    <span class="yarpp-thumbnail-title">at lacinia massa</span>
    </a>

    So if you’re setting the “Alternative Text” on your media when it’s uploaded, and you’re happy with the “title” coming from the post’s name, then you shouldn’t need to do anything differently.

    Does that answer your question? Or is there something else you were wanting?

    Thread Starter Okoth1

    (@okoth1)

    Yes, no problem Michael, it’s just that I saw other questions being answered. I hope you’re OK.

    All of my images have alt, title and caption fields filled in. All images are added/used as Featured images on single posts and I have the feeling it has something to do with the Featured images.

    But even when I add attributes manually they won’t show up.

    $post_thumbnail_html = get_the_post_thumbnail(null, $dimensions['size'], array('data-pin-nopin' => 'true', 'title' => 'WontShowTitle', 'alt' => 'WontShowAlt', 'class' => 'classNoProblem') );

    It would be great if you know a solution for this.

    Thanks

    Plugin Support Michael Nelson

    (@mnelson4)

    Hmmm, could you provide a URL of a page where you’re having this issue? And where is that code being placed?

    Thread Starter Okoth1

    (@okoth1)

    Hi Michael,

    This page has the issue
    https://www.dapurkobe.co.id/burger-tempe-crispy

    but all other single recipe page has it.

    The code I put in plugins/yet-another-related-posts-plugin/includes/template_thumbnails.php around line 38

    Thread Starter Okoth1

    (@okoth1)

    I’m getting the alt and title names of featured images on other places this way

    $alt_name = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
    $title_name = get_the_title($image_id);

    If you could echo the values into
    $post_thumbnail_html = get_the_post_thumbnail(null, $dimensions['size'], array('data-pin-nopin' => 'true', 'title' => 'title_name', 'alt' => 'alt_name' , 'class' => 'optional_class_name') );

    it might be solved.

    https://wordpress.stackexchange.com/questions/193196/how-to-get-image-title-alt-attribute/330599

    • This reply was modified 4 years, 6 months ago by Okoth1.
    Plugin Support Michael Nelson

    (@mnelson4)

    Hmmm I see the <a> actually *does* at least have a title attribute, but yes I see the alt attribute is missing.

    Just double-checking: I made a video showing how I’m adding the alt tags onto images, in case we’re doing something different: https://drive.google.com/file/d/1eqf7BJfXW98IkZvqWYKpwHt0YwrSXkcE/view?usp=drivesdk

    But I’d say that if you’re modifying YARPP’s code directly to add the alt tags, and they’re still not appearing, I suspect some other plugin, or maybe your theme, is filtering the HTML produced. If you have a test site, I’d suggest deactivating other plugins to find out which. But YARPP by itself doesn’t have this issue (or at least I can’t see how it does.)

    Thread Starter Okoth1

    (@okoth1)

    Do you have an example were you add an image directly as featured post and that image will have an alt text on the website?

    I think WordPress removed the alt text for featured posts from version 4.9.

    I don’t think one of my plugins cause this.

    Thread Starter Okoth1

    (@okoth1)

    I’m deactivating plugins and made some progress. You might be right, mister ??

    I’m going to find out what’s causing it and let you know.

    Thanks

    Thread Starter Okoth1

    (@okoth1)

    I found the plugin that’s causing it and I’ll notify the creator.

    Thank you for pointing me in the right direction.

    Plugin Support Michael Nelson

    (@mnelson4)

    Phew! Good guess! (Actually it’s a pretty common response: when you don’t understand what’s going wrong: blame another plugin! ??)
    Thanks for tracking it down @okoth1.
    And that was a very good-looking site. Well done! And take care!

    Thread Starter Okoth1

    (@okoth1)

    Hi Michael,

    I fully agree on this “blame another plugin!” And then people expect me to deactivate all plugins, which basically means to take the site offline… ??

    This site is from a period before people use their phones to browse online. ?? It’s still working but it’s going to get a mobile friendly design. I’m glad you like it.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Alt and title attribute’ is closed to new replies.