Skip to content

Commit

Permalink
Merge branch 'main' of github.com:adampatterson/Axe-Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
adampatterson committed Jan 26, 2024
2 parents a7c00dd + b127761 commit 12edad6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,36 @@ function setBaseDataPath()
}
}
}

if (!function_exists('getFeaturedImage')) {

/**
* @param $post_id
* @param $size
* @return mixed
*
* getFeaturedImage($post->ID, 'featured');
*
*/
function getFeaturedImage($post_id, $size = 'featured')
{
$thumb_id = get_post_thumbnail_id($post_id);
$img = wp_get_attachment_image_src($thumb_id, $size);
$meta = get_post_meta($thumb_id);

// If there's no image, then there's no post meta, return false.
if (!$meta && !$img) return false;

$meta_attachment = unserialize($meta['_wp_attachment_metadata'][0]);

return [
'url' => $img[0],
'width' => $img[1],
'height' => $img[2],
'meta' => $meta_attachment,
'image_meta' => $meta_attachment['image_meta'],
//'image_sizes' => $meta_attachment['sizes'],
'alt' => $meta['_wp_attachment_image_alt'][0]
];
}
}

0 comments on commit 12edad6

Please sign in to comment.