Skip to content

Instantly share code, notes, and snippets.

@theJasonJones
Last active March 30, 2017 16:28
Show Gist options
  • Save theJasonJones/c17cf5e484283cc9ab86dc290aaca58f to your computer and use it in GitHub Desktop.
Save theJasonJones/c17cf5e484283cc9ab86dc290aaca58f to your computer and use it in GitHub Desktop.
Alt Filler

Image Alt Attribute filler

Put this helper function your functions.php file and pass in an argument (or don't). This way you're alt attribute is always filled out for every image on your site.

This checks to see if the alt attribute is assigned in the WordPress media library and returns that or it just returns the name of the site.

Tip: Use Advanced Custom Fields for the alt attribute.

// @param string
// @returns echo of alt
//
function alt_filler( $img_alt = '' ){
if( empty( $img_alt ) ){
return get_bloginfo();
}
echo $img_alt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment