0

I am developing my own theme and for logo I use tag:

<?php
   $image_url = get_theme_mod( 'header_logo_image_home', '' );
   $image_id = attachment_url_to_postid($image_url );
?>
   <picture class="lozad" data-src="<?php echo wp_get_attachment_image_src( $image_id, 'logo' )[0]; ?> 1x, <?php echo wp_get_attachment_image_src( $image_id, 'logo-retina' )[0]; ?>  2x" data-alt="====> ? HOW ? <====">
   <source srcset="<?php echo wp_get_attachment_image_src( $image_id, 'logo' )[0]; ?>  1x, <?php echo wp_get_attachment_image_src( $image_id, 'logo-retina' )[0]; ?>  2x">
   </picture>

Is there any way do get ALT based on 'attachment_url_to_postid'?

PS: I use element with lozad.js lazyload script.

Thanks!

4
  • Question: why did you type data-alt instead of just alt?
    – jsmod
    Commented Mar 20, 2019 at 2:09
  • It's part of lozad.js... Commented Mar 20, 2019 at 2:49
  • Thank you for clarifying that :) I haven't used lozad.js before. Have you tried this: $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);? It's from another answer to a similar question here: https://wordpress.stackexchange.com/a/330599/160457.
    – jsmod
    Commented Mar 20, 2019 at 5:19
  • Glad to be of assistance. Perhaps you can give the original posters of that thread an up-vote so others can find it, too? https://wordpress.stackexchange.com/a/330599/160457
    – jsmod
    Commented Mar 20, 2019 at 17:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.