Last active
May 20, 2018 10:36
-
-
Save mdjwel/d19b1fc0c49155bc84d26d0a36ed85c0 to your computer and use it in GitHub Desktop.
Get image alt text in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get image alt text | |
function aproch_image_alt($image_id) { | |
$image_title = get_the_title($image_id); | |
$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true); | |
echo !empty($image_alt) ? $image_alt : $image_title; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment