Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
162 views
in Q2A Core by
edited by

image alt problem

<img src="./?qa=image&amp;qa_blobid=3153732008858225060&amp;qa_size=500" width="500" height="500" class="qa-avatar-image" alt="">

alt tag empty on all blobid images? Tell Me How to Fix It? and I want to fill this tag with UserName?

ago by
Just an FYI, having a blank alt text *is* valid HTML, if the image is only decorative like an icon or avatar.

2 Answers

+4 votes
by
edited by

Hello Tech Guru. Welcome!

There are two workarounds for adding user handles in the alt attribute:

Method 1: Modify function qa_get_user_avatar_html() in qa-include/app/users.php and add the following line after line 675:

    // Add user handle in 'alt' HTML attribute
    $html = str_replace('" alt=""', '" alt="' . qa_html($handle) . '"', $html);
  • Pros: Quick and easy way of getting the result you intended
  • Cons: It'll get reverted to its initial form after updating Q2A

Method 2: Override function qa_get_user_avatar_html() via plugin.

function qa_get_user_avatar_html($flags, $email, $handle, $blobId, $width, $height, $size, $padding = false)
{
    $html = qa_get_user_avatar_html_base($flags, $email, $handle, $blobId, $width, $height, $size, $padding);

    // Add user handle in 'alt' HTML attribute
    if ($html)
        $html = str_replace('" alt=""', '" alt="' . qa_html($handle) . '"', $html);

    return $html;
}

There's a great tutorial about how to create a plugin at https://docs.question2answer.org/plugins/tutorial/

  • Pros: It'll work after Q2A updates
  • Cons: None

This answer assumes you're willing to make it work by yourself, but I'll give you
a few suggestions just in case you find it difficult:

  • Add a comment below, I (and other community members) can try to help you out.
  • Find a developer friend and ask him to implement it for you.
  • Get consultancy from one of the service providers or send me a private message.

Thank you for reading.

by
Is there anything wrong in doing this change in core? I mean it should be in Q2A by default right?
by
I agree with you arjunsuresh. There's nothing wrong with it.
by
Thank you, that worked nicely.
0 votes
by

@jair I added this code in the way you showed me for the same problem. For this I gave a picture after adding the code, see if it is ok? Tell me if there is any problem.

by
Check again if I was able to place the code correctly. Link:
https://ibb.co/0jCmb3s
by
Yes, that's correct.
by
Thank you very much.
by
+1
I'm glad it worked for you.
...