Last active
April 1, 2019 08:08
-
-
Save w-perspective/2d5ab4b06c5125f7a56bd7354e9fbc43 to your computer and use it in GitHub Desktop.
WP generate alt attribute to <img>(author campusboy)
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
| /** | |
| * Заполняет поле для атрибута 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