@smittyhead The issue is because you’re using echo as well as block_field(), which also echoes. You could reformat your template like this:
<?php
if ( ! empty( block_value( 'title-link' ) ) ) {
echo '<a href="' . block_value( 'title-link' ) . '">' . block_value( 'title' ) . '</a>';
} else {
echo '<div>' . block_value( 'title' ) . '</div>';
}
?>
Or, alternatively…
<?php if ( ! empty( block_value( 'title-link' ) ) ) : ?>
<a href="<?php block_field( 'title-link' ); ?>"><?php block_field( 'title' ); ?></a>
<?php else : ?>
<div><?php block_field( 'title' ); ?></div>
<?php endif; ?>
Thank you so much! Sorry for such a noob question.
Hi, sorry, but having this same issue in trying to solve another problem for a different post but since was relevant to this issue thought it would be better to move to this post.
Instead of an if statement i’m setting up variables but I cannot get ’empty’ to work with that, i’m getting the output for the block_value, this is the setup:
<?php
$image_url = block_field( 'image-1' );
$image_id = pippin_get_image_id($image_url);
$image_med = wp_get_attachment_image_src($image_id, 'medium_large');
?>
-
This reply was modified 7 years ago by
smittyhead.
@smittyhead Same problem again:
$image_url = block_value( 'image-1' );
Damn, you know, i glossed over that part! Thanks for your patience.