-
-
Save barbareshet/73269e4f6833ce84a7fc00687af55c56 to your computer and use it in GitHub Desktop.
Output Inline SVGs from ACF image field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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