Title: Toggle issue
Last modified: March 19, 2019

---

# Toggle issue

 *  Resolved [smittyhead](https://wordpress.org/support/users/smittyhead/)
 * (@smittyhead)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/toggle-issue-2/)
 * I’m trying to add a switch that tells if a text field is a link or not then using
   the code in the block like below. It works fine except it outputs plain text 
   of the two fields as well as the html in the echo. I’m not sure what i’m doing
   wrong?
 *     ```
       <div><?php block_field( 'number' ) ?></div>
       <?php
       if ( block_value( 'title-link' ) ) {
       	echo "<a href='#'>" . block_field( 'title' ) . "</a>";
       }else {
           echo "<div>" . block_field( 'title' ) . "</div>" ;
       }
       ?> 
       ```
   

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Luke Carbis](https://wordpress.org/support/users/lukecarbis/)
 * (@lukecarbis)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/toggle-issue-2/#post-11328669)
 * [@smittyhead](https://wordpress.org/support/users/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; ?>
       ```
   
    -  This reply was modified 7 years, 2 months ago by [Luke Carbis](https://wordpress.org/support/users/lukecarbis/).
 *  Thread Starter [smittyhead](https://wordpress.org/support/users/smittyhead/)
 * (@smittyhead)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/toggle-issue-2/#post-11328799)
 * Thank you so much! Sorry for such a noob question.
 *  Plugin Author [Luke Carbis](https://wordpress.org/support/users/lukecarbis/)
 * (@lukecarbis)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/toggle-issue-2/#post-11329209)
 * Not a problem at all!
 *  Thread Starter [smittyhead](https://wordpress.org/support/users/smittyhead/)
 * (@smittyhead)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/toggle-issue-2/#post-11333001)
 * 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, 2 months ago by [smittyhead](https://wordpress.org/support/users/smittyhead/).
 *  Plugin Author [Luke Carbis](https://wordpress.org/support/users/lukecarbis/)
 * (@lukecarbis)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/toggle-issue-2/#post-11337672)
 * [@smittyhead](https://wordpress.org/support/users/smittyhead/) Same problem again:
   `
   $image_url = block_value( 'image-1' );`
 *  Thread Starter [smittyhead](https://wordpress.org/support/users/smittyhead/)
 * (@smittyhead)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/toggle-issue-2/#post-11337768)
 * Damn, you know, i glossed over that part! Thanks for your patience.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Toggle issue’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/block-lab_5c34e8.svg)
 * [Block Lab](https://wordpress.org/plugins/block-lab/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/block-lab/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/block-lab/)
 * [Active Topics](https://wordpress.org/support/plugin/block-lab/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/block-lab/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/block-lab/reviews/)

## Tags

 * [toggle](https://wordpress.org/support/topic-tag/toggle/)

 * 6 replies
 * 2 participants
 * Last reply from: [smittyhead](https://wordpress.org/support/users/smittyhead/)
 * Last activity: [7 years, 2 months ago](https://wordpress.org/support/topic/toggle-issue-2/#post-11337768)
 * Status: resolved