Created
July 20, 2016 22:14
-
-
Save derekshirk/f2c1bb844a5bc98a038cc40fdb5f559a 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; ?> |
echo file_get_contents( get_site_url().$url ) ;
to avoid failed to open stream error.
Why? The url from the image field is a full none relative URL.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
echo file_get_contents( get_site_url().$url ) ;
to avoid failed to open stream error.