Having successfully uploaded an SVG image through WordPress's back-end media uploader with the help of a third party plugin such as Safe SVG by Daryll Doyle, how can one get the image's dimensions that are stored in the SVG file's width
, height
, or viewBox
attributes to use in front-end with WordPress functions such as wp_get_attachment_image_src()
?
Unlike other types of images such as PNG and JPEG, WordPress does not store SVG image's dimensions into its system.
Maybe there's some kind of hook we could use in theme's functions.php
that fires whenever you upload a file through WordPress's back-end in order to acquire those dimensions and write them directly into the database for that attachment?
Thanks!