• Resolved pepe80

    (@pepe80)


    Hi,
    I’ve noticed that the wp_get_attachment_image_srcset() function returns null when uploaded file has .svg extension. I know that your plugin only allows to upload SVG to WP library and shows thumbnail but maybe you have any idea about it? 🙂

    On my website user can upload a separate file for desktop view and a separate file for mobile view. Any format is allowed (jpg/png/svg). My code:

    <?php
    	$image_desktop_id = get_field('image_desktop_id');
    	$image_mobile_id = get_field('image_mobile_id');
    	$image_default_src = wp_get_attachment_image_src($image_desktop_id, 'full');
    ?>
    
    <picture>
    	<source media="(max-width: 750px)" srcset="<?php echo wp_get_attachment_image_srcset($image_mobile_id); ?>">
    	<source media="(min-width: 751px)" srcset="<?php echo wp_get_attachment_image_srcset($image_desktop_id); ?>">
    	<img src="<?php echo $image_default_src[0]; ?>" srcset="<?php echo wp_get_attachment_image_srcset($image_desktop_id); ?>">
    </picture>
Viewing 1 replies (of 1 total)
  • Plugin Contributor kubiq

    (@kubiq)

    Hello,

    you can not have srcset for SVG image, because SVG can not be scaled by WordPress – you can not create thumbnails or different sizes from SVG file.

    Just use the wp_get_attachment_image_src or get URL directly, but you can not use any function that is trying to create additional sizes for image if it’s SVG.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_get_attachment_image_srcset returns false’ is closed to new replies.