php - Removing frontend dependancies from WordPress Advanced Custom Fields -
i'm trying make theme totally independent of acf's get_field
, the_field
(so in case plugin disabled site not break). have image loaded via custom field 'slider_image'
inline background-image
. need call url of image. possible load inlined html? here's working code (w/ acf's the_field
):
<!-- hero image --> <section class="hero" style="background: url('<?php the_field('slider_image'); ?>') no-repeat center center; background-size: cover;"> </section> <!-- end hero image -->
how can use get_post_meta
rewrite statement in case plugin disabled?
i've tried:
<section class="hero" style="background: url('<?php echo get_post_meta( get_the_id(), 'slider_image', true ); ?>') no-repeat center center; background-size: cover;">
which returns:
<section class="hero" style="background: url('98') no-repeat center center; background-size: cover;">
this must id of post attached image. grab current image must use of embedded wp functions wp_get_attachment_image (if want print image tag) or wp_get_attachment_image_src (if want image attributes)
for example in case, when want url
of image can this:
$img_id = get_post_meta( get_the_id(), 'slider_image', true ); $image_attr = wp_get_attachment_image_src( $img_id, 'large' ); //returns false or array if ( $image_attr ) { $img_url = $image_attr[0]; ?> <section class="hero" style="background: url('<?php echo $img_url; ?>') no-repeat center center; background-size: cover;"> <?php } ?>
Comments
Post a Comment