Source link plugin – show just anchor / link

I implemented a small source link plugin on my WordPress website via the following codes.

Single.php:

                        <?php global $  post, $  pages, $  page;  $  total = count( $  pages ); // Link źródłowy if ( $  total < 2 || $  page === $  total ) :          if ( $  url = get_post_meta( $  post->ID, '_source_link', true ) ) :         $  label = get_post_meta( $  post->ID, '_source_link_label', true );         $  label = $  label ? $  label : $  url;     ?>         <div class="source-link">             <b>Źródło:</b> <a href="<?php echo esc_url( $  url ); ?>" rel="nofollow" target="_blank"><?php                 echo esc_html( $  label ); ?></a>         </div>     <?php endif;  endif;  ?> 

Functions.php:

add_action( 'add_meta_boxes', 'wpse_source_link' );   add_action( 'save_post', 'wpse_source_link_save' );   function wpse_source_link() {      add_meta_box(         'source_link',         __( 'Link źródłowy', 'myplugin_textdomain' ),          'wpse_source_meta_box',         'post',         'side'     ); }   function wpse_source_meta_box( $  post ) {      wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );       echo '<label for="source-link">Link</label> ';   echo '<input type="text" id="source-link"" name="source_link" value="'.     get_post_meta( $  post->ID, '_source_link', true ) .'" size="25" />';    echo '<label for="source-link-label">Nazwa strony</label> ';   echo '<input type="text" id="source-link-label"" name="source_link_label" value="'.     get_post_meta( $  post->ID, '_source_link_label', true ) .'" size="25" />'; }   function wpse_source_link_save( $  post_id ) {    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )        return;    if ( ! wp_verify_nonce( $  _POST['myplugin_noncename'], plugin_basename( __FILE__ ) ) )       return;     if ( current_user_can( 'edit_post', $  post_id ) ) {        update_post_meta( $  post_id, '_source_link', sanitize_text_field( $  _POST['source_link'] ) );       update_post_meta( $  post_id, '_source_link_label', sanitize_text_field( $  _POST['source_link_label'] ) );     } } 

As you can see there are two fields: Link źródłowy (Source link) and Nazwa strony (website name – anchor). However, at this moment this plugin only works, when both fields have some text inside. Is there any way to make it work also with just anchor/link? I mean, if two fields are completed it should show anchor with link, but if just anchor has some text in it, then it should show only anchor. Same goes for link.

Does anyone know how to make it work like that? To be honest I’m a newbie and I have no idea.