Tuesday, June 26th, 2018
Make sure your image field is set to an array in ACF and then use the below.
‘150px’ is the maximum width your image will ever display.
Click the link to view the code
Tags: ACF, Functions, Responsive images, SRCSET, WordPress
Posted in PHP, WordPress | No Comments »
Friday, March 25th, 2016
You can use thumbnail, medium, large or full as the sizes variable to serve the size image you require.
<?php $image = get_field('the_image'); ?>
<img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['caption']; ?>" />
Tags: ACF, Advanced custom fields, Array, Full, Image, Image sizes, Medium, Thumbnail
Posted in PHP, WordPress | No Comments »
Tuesday, March 8th, 2016
<?php if( get_field('video_url') ):?>
Show this if field exists <?php the_field('video_url');?>
<?php else : ?>
Show this if not
<?php endif;?>
Tags: ACF, Empty fields, PHP, WordPress
Posted in PHP, WordPress | No Comments »
Wednesday, February 24th, 2016
Useful code for Advanced custom fields (ACF) flexible content – perfect for page builders
<?php
if( have_rows('pagebuilder') ):
while ( have_rows('pagebuilder') ) : the_row();
if( get_row_layout() == 'hero' ):
get_template_part( 'assets/parts/pagebuilder/hero');
elseif( get_row_layout() == 'call_to_action' ):
get_template_part( 'assets/parts/pagebuilder/call-to-action');
endif;
endwhile;
else :
// no layouts found
endif;
?>
Tags: ACF, Custom Fields, Flexible content, Page builder, WordPress
Posted in PHP, WordPress | No Comments »