Wordpress Custom Logo

Viewed 271

I'm pretty new about coding, and i'm trying to build a Wordpress custom theme. I'm stacked on the logo section and I really can't understand what i'm doing wrong:

<?php if ( get_theme_mod('apc_logo_image', '') != '' ): ?>
        <img class="animate" src="<?php echo get_template_directory_uri(); ?>/img/logo.png" alt="logo sito">
    <?php elseif ( is_front_page() && is_home() ) : ?>
        <img class="animate" src="<?php echo get_theme_mod( 'apc_logo_image', '' ); ?>" alt="<?php echo get_theme_mod( 'apc_logo_alt_text', '' ); ?>">
    <?php else : ?>
        <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
    <?php endif; ?>

I would like to do the follow: If I upload an images from Customizer, than it would be visible as logo. If don't and i have a logo in a specific path like: /assets/logo ecc... than it should be visible like logo. if don't, then I would like to see the name of the website as it should be.

1 Answers

So working code:

 <?php 
  $logoFile = $_SERVER['DOCUMENT_ROOT'] . '/wp-content/themes/' . wp_get_theme()->get('TextDomain') . '/assets/images/logo/logo.png';
  if ( (bool)get_theme_mod('apc_logo_image')) : ?>
     <img class="animate" src="<?php echo get_theme_mod( 'apc_logo_image'); ?>" alt="<?php echo get_theme_mod( 'apc_logo_alt_text'); ?>"> 
     <?php else : ?> 
        <?php if ( file_exists($logoFile) ) : ?> 
        <img class="animate" src="<?php echo '/wp-content/themes/' . wp_get_theme()->get('TextDomain') . '/assets/images/logo/logo.png'?>" alt="logo sito"> 
        <?php else : ?> 
        <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1> 
        <?php endif; ?> 
    <?php endif ?>
Related