Replace site title with logo when logo is uploaded in customizer using

Solved:

<div class="site-branding">             
    <?php
    $logo_id = get_theme_mod( 'custom_logo' );
    $logo_image = wp_get_attachment_image_src( $logo_id, 'full' );                  

    if ( ! empty( $logo_image ) ) : ?>
        <span class="site-logo"><a href="https://wordpress.stackexchange.com/questions/265299/<?php echo esc_url( home_url("https://wordpress.stackexchange.com/" ) ); ?>" rel="home"><img src="<?php echo esc_url( $logo_image[0] ); ?>" alt="<?php bloginfo( 'name' ); ?>"/></a></span>
    <?php else : ?>
        <h1 class="site-title"><a href="https://wordpress.stackexchange.com/questions/265299/<?php echo esc_url( home_url("https://wordpress.stackexchange.com/" ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
    <?php
    endif;      
</div><!-- .site-branding -->

error code: 523