Hello
I’m trying to overwrite the alt and title attributes of images
I can’t insert the brand name (text) in output.
It’s return the value “Array”
Will be nice you can help me with this.
Thanks
this is my code
add_filter('wp_get_attachment_image_attributes', 'change_attachement_image_attributes', 20, 2);
function change_attachement_image_attributes( $attr, $attachment ){
global $post, $product;
// 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);
$sku = get_post_meta( $post->ID, '_sku', true );
// $brand = get_post_meta( $post->ID, '_et_primary_category', true );
$brand = wp_get_post_terms( $post->ID, 'brand', array( 'fields' => 'all' ));
$attr['alt'] = $sku . ' | ' . $title . ' | ' . $brand;
$attr['title'] = $title;
return $attr;
}