Created
October 30, 2019 13:04
-
-
Save shrinkray/fb4ab0dfba74f2e275b3bbb98c8a2fde to your computer and use it in GitHub Desktop.
Display the featured image with the alt tag using get_the_post_thumbnail_url();
This file contains hidden or 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
| /** | |
| * To display the featured image with the alt tag | |
| * | |
| * @link: https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/ | |
| * @author: https://profiles.wordpress.org/thelilmercoder/ | |
| */ | |
| $thumbnail = get_the_post_thumbnail_url(); | |
| if ( $thumbnail ) { | |
| $alt_text = get_post_meta( $thumbnail->ID, '_wp_attachment_image_alt', true ); | |
| if ( ! empty( $thumbnail ) ) { | |
| if ( ! empty( $alt_text ) ) { | |
| $alt_text = $alt_text; | |
| } else { | |
| $alt_text = __( 'no alt text set', 'textdomain' ); | |
| } | |
| echo ''; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment