Skip to content

Instantly share code, notes, and snippets.

@w-perspective
Last active April 1, 2019 08:08
Show Gist options
  • Select an option

  • Save w-perspective/2d5ab4b06c5125f7a56bd7354e9fbc43 to your computer and use it in GitHub Desktop.

Select an option

Save w-perspective/2d5ab4b06c5125f7a56bd7354e9fbc43 to your computer and use it in GitHub Desktop.
WP generate alt attribute to <img>(author campusboy)
/**
* Заполняет поле для атрибута alt на основе заголовка изображения при его вставки в контент поста.
*
* @param array $response
*
* @return array
*/
function change_empty_alt_to_title( $response ) {
if ( ! $response['alt'] ) {
$response['alt'] = sanitize_text_field( $response['title'] );
}
return $response;
}
add_filter( 'wp_prepare_attachment_for_js', 'change_empty_alt_to_title' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment