Skip to content

Instantly share code, notes, and snippets.

@cliftonc0613
Forked from derekshirk/acf-inline-svg.php
Created December 7, 2018 15:47
Show Gist options
  • Save cliftonc0613/23c8680e4226a3b83f17946513fc4dc4 to your computer and use it in GitHub Desktop.
Save cliftonc0613/23c8680e4226a3b83f17946513fc4dc4 to your computer and use it in GitHub Desktop.
Output Inline SVGs from ACF image field
<?php
/* ————————————————————————— */
/* ACF Inline SVGs
/* ————————————————————————— */
$repeater = 'repeater_field_name'
if ( have_rows( $repeater ) ): ?>
<section class="content-main">
<div class="container"> <?php
while ( have_rows( $repeater ) ) : the_row();
$icon = get_sub_field( 'icon' );
if ( !empty( $icon ) ):
$url = $icon['url'] ;
$ext = pathinfo( $url, PATHINFO_EXTENSION ); ?>
<div class="icons"> <?php
if ( $ext == 'svg' ):
echo file_get_contents( $url ) ;
// Non SVG Fallback
else: ?>
<img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>"> <?php
endif; ?>
</div> <?php
endif;
endwhile; ?>
</div>
</section> <?php
endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment