Created
January 23, 2017 16:24
-
-
Save marciomassari/9c3a156ceb40fe2e32d3bbc61f1d561b to your computer and use it in GitHub Desktop.
Alt WP Images
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
| <?php | |
| if(empty($alt_text)) // If not, Use the Caption | |
| { | |
| $attachment = get_post($post->ID); | |
| $alt_text = trim(strip_tags( $attachment->post_excerpt )); | |
| } | |
| if(empty($alt_text)) // Finally, use the title | |
| { | |
| $attachment = get_post($post->ID); | |
| $alt_text = trim(strip_tags( $attachment->post_title )); | |
| } | |
| <? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment