Support » Plugin: Perfect Brands for WooCommerce » add brand to image alt tag

  • Resolved khalil43


    Hi, first let me thank you for this great plugin.
    i’d like to use this code to add automatically product name and product brand to the alt text of images. `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;
    is there a way to get the product brand ?
    Thank you very much

Viewing 1 replies (of 1 total)
  • Plugin Contributor titodevera


    Hi khalil43,

    You can do it using the get_the_terms() function, something like this:

    get_the_terms( $product_id, 'pwb-brand' );

    More info here


Viewing 1 replies (of 1 total)
  • The topic ‘add brand to image alt tag’ is closed to new replies.