admin管理员组文章数量:1130349
How to get the URL from an image with custom image size to use as a background-image from AFC?
Register size in functions.php:
add_theme_support( 'post-thumbnails' );
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop
Display image with custom size (named: customsize) on page with ACF:
<?php $image = get_field('image_field'); ?>
<img src="<?php echo $image['sizes']['customsize']; ?> />
But how to display image as background image with ACF?:
<?php $image = get_field('image_field'); ?>
<div style="background-image: url(<?php $image['url'] ?>)" /></div>
How to get the URL from an image with custom image size to use as a background-image from AFC?
Register size in functions.php:
add_theme_support( 'post-thumbnails' );
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop
Display image with custom size (named: customsize) on page with ACF:
<?php $image = get_field('image_field'); ?>
<img src="<?php echo $image['sizes']['customsize']; ?> />
But how to display image as background image with ACF?:
<?php $image = get_field('image_field'); ?>
<div style="background-image: url(<?php $image['url'] ?>)" /></div>
Share
Improve this question
asked Jan 2, 2019 at 18:08
LudoLudo
612 silver badges11 bronze badges
1
- what is the HTML output when you run your last snippet? – RiddleMeThis Commented Jan 2, 2019 at 18:14
1 Answer
Reset to default 1First off, this code...
<img src="<?php echo $image['sizes']['customsize']; ?> />
is missing the end quote, it should be...
<img src="<?php echo $image['sizes']['customsize']; ?>" />
You can use that same php to output the URL for the background size.
<div style="height: 300px; width: 300px; background-image: url(<?php echo $company_logo['sizes']['customsize']; ?>)" /></div>
Tested and works.
How to get the URL from an image with custom image size to use as a background-image from AFC?
Register size in functions.php:
add_theme_support( 'post-thumbnails' );
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop
Display image with custom size (named: customsize) on page with ACF:
<?php $image = get_field('image_field'); ?>
<img src="<?php echo $image['sizes']['customsize']; ?> />
But how to display image as background image with ACF?:
<?php $image = get_field('image_field'); ?>
<div style="background-image: url(<?php $image['url'] ?>)" /></div>
How to get the URL from an image with custom image size to use as a background-image from AFC?
Register size in functions.php:
add_theme_support( 'post-thumbnails' );
add_image_size( 'homepage-thumb', 220, 180 ); // Soft Crop
Display image with custom size (named: customsize) on page with ACF:
<?php $image = get_field('image_field'); ?>
<img src="<?php echo $image['sizes']['customsize']; ?> />
But how to display image as background image with ACF?:
<?php $image = get_field('image_field'); ?>
<div style="background-image: url(<?php $image['url'] ?>)" /></div>
Share
Improve this question
asked Jan 2, 2019 at 18:08
LudoLudo
612 silver badges11 bronze badges
1
- what is the HTML output when you run your last snippet? – RiddleMeThis Commented Jan 2, 2019 at 18:14
1 Answer
Reset to default 1First off, this code...
<img src="<?php echo $image['sizes']['customsize']; ?> />
is missing the end quote, it should be...
<img src="<?php echo $image['sizes']['customsize']; ?>" />
You can use that same php to output the URL for the background size.
<div style="height: 300px; width: 300px; background-image: url(<?php echo $company_logo['sizes']['customsize']; ?>)" /></div>
Tested and works.
本文标签: How use custom image sizeACFbackground image
版权声明:本文标题:How use custom image size + ACF + background image 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749050262a2308504.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论