Автоматическое создание Alt и Title для изображений WordPress без модулей через functions.php
Добавляем эти строки в конец файла functions.php
/**
* Create Alt and Title Image
*/
function change_attachement_image_attributes( $attr, $attachment ) {
// Get post parent
$parent = get_post_field( 'post_parent', $attachment );
// Get post type to check if it's product
$type = get_post_field( 'post_type', $parent );
if ( $type != 'product' ) {
return $attr;
}
/// Get title
$title = get_post_field( 'post_title', $parent );
$attr['alt'] = $title . ' - Кастомный Текст после Alt';
$attr['title'] = $title . ' - Кастомный Текст после Title';
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2 );
