Last active
June 5, 2020 04:53
-
-
Save 10h30/dc05e398e1092f9ffb2f to your computer and use it in GitHub Desktop.
Use woocommerce product name as product image alt & titleFrom http://stackoverflow.com/questions/27087772/how-can-i-change-meta-alt-and-tilte-in-catalog-thumbnail-product-thumbnail
This file contains 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
add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2); | |
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; | |
$attr['title'] = $title; | |
return $attr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment