Skip to content

Instantly share code, notes, and snippets.

@dhirenpatel22
Created July 19, 2026 06:16
Show Gist options
  • Select an option

  • Save dhirenpatel22/ae059b41bd0f210a4de0a81d65654aa5 to your computer and use it in GitHub Desktop.

Select an option

Save dhirenpatel22/ae059b41bd0f210a4de0a81d65654aa5 to your computer and use it in GitHub Desktop.
Update image alt text to use media metadata
<?php
if ( $image_id ) {
$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
$icon_html = wp_get_attachment_image(
$image_id,
$atts['size'],
false,
array(
'class' => 'product-cat-icon',
'loading' => 'lazy',
'alt' => esc_attr( $image_alt ?: $primary_term->name ),
)
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment