I have created a custom field with Advanced Custom Fields for my posts. My variable is set product_image, so I can print it with:
<?php the_field('product_image'); ?>
But I need to print it in my site-header section, within header.php, only for single posts.
<?php if( is_single('post') ) { ?>
<img src="<?php the_field('product_image'); ?>">
<?php } else { ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img src="<?php echo esc_url( home_url( '/' ) ); ?>/logo.png">
</a>
<?php } ?>
And it doesn't work.
I have created a custom field with Advanced Custom Fields for my posts. My variable is set product_image, so I can print it with:
<?php the_field('product_image'); ?>
But I need to print it in my site-header section, within header.php, only for single posts.
<?php if( is_single('post') ) { ?>
<img src="<?php the_field('product_image'); ?>">
<?php } else { ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<img src="<?php echo esc_url( home_url( '/' ) ); ?>/logo.png">
</a>
<?php } ?>
And it doesn't work.
Share Improve this question asked Apr 5, 2019 at 7:58 CatalinCatalin 235 bronze badges1 Answer
Reset to default 2You can pass the post id as the 2nd argument on the_field
.
global $post;
the_field('product_image', $post->ID);
or
the_field('product_image', get_the_ID());
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745624971a4636751.html
评论列表(0条)