If anyone can help it would be much appreciated. I'm working on a Wordpress site and I have a header image on the homepage. It's only showing up on the homepage but I need it to show on every page. I found this code in the header.php file which I believe needs to be changed, but I'm not very familiar with php.
This is the code for the header image in the header.php file:
<?php if ( is_home() || is_front_page() ) { ?>
<?php if ( get_header_image() != '' && $papercuts_options_db['papercuts_display_header_image'] != 'Everywhere except Homepage' ) { ?>
<div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
<?php
}
} else { ?>
<?php if ( get_header_image() != '' && $papercuts_options_db['papercuts_display_header_image'] != 'Only on Homepage' ) { ?>
<div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
<?php }
} ?>
Replace the code with this:
<?php
if ( get_header_image() != '' ) {
?>
<div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
<?php
}
?>
And ideally keep the original code but commented out - use:
<?php
/*
if ( is_home() || is_front_page() ) { ?>
<?php if ( get_header_image() != '' && $papercuts_options_db['papercuts_display_header_image'] != 'Everywhere except Homepage' ) { ?>
<div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
<?php
}
} else { ?>
<?php if ( get_header_image() != '' && $papercuts_options_db['papercuts_display_header_image'] != 'Only on Homepage' ) { ?>
<div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
<?php }
}
*/ ?>
For reference
<?php if ( get_header_image() !='') { ?>
<div class="header-image-wrapper"><div class="header-image"><img src="<?php header_image(); ?>" alt="<?php bloginfo( 'name' ); ?>" /></div></div>
<?php
} ?>
Replace the code with above. I think it will work.
Related
i would like to display a different logo in home page (with ACF).
i try with this code but it doesn't work :
<?php if(is_home()){ ?>
<?php $logo = get_field( 'logo', 'option' ); ?>
<?php if ( $logo ) { ?>
<a href="<?php echo home_url(); ?>" class="navbar-brand">
<img src="<?php echo $logo['url']; ?>" alt="" />
</a>
<?php } ?>
<?php } else { ?>
<?php $logo_footer = get_field( 'logo_footer', 'option' ); ?>
<?php if ( $logo_footer ) { ?>
<a href="<?php echo home_url(); ?>" class="navbar-brand">
<img src="<?php echo $logo_footer['url']; ?>" alt="" />
</a>
<?php } ?>
<?php } ?>
Do you have any tips ?
thank you
If you have set the homepage in Settings->Reading->Your homepage, you'll have to use is_front_page() instead of is_home().
More information here: https://wordpress.stackexchange.com/a/30389
Add This code into your php file where you want to add it.
i hope its working.
<?php
$logo = get_field( 'logo', 'option' );
$logo_footer = get_field( 'logo_footer', 'option' ); ?>
<?php if ( $logo ) { ?>
<a href="<?php echo home_url(); ?>" class="navbar-brand">
<img src="<?php echo $logo['url']; ?>" alt="" />
</a>
<?php } ?>
<?php if ( $logo_footer ) { ?>
<a href="<?php echo home_url(); ?>" class="navbar-brand">
<img src="<?php echo $logo_footer['url']; ?>" alt="" />
</a>
<?php } ?>
I'm trying to use WordPress' new custom logo feature to accomplish the following:
Display a default/fallback logo.
If WordPress version supports custom logo, allow user to replace the default/fallback logo with a custom logo in the Customizer.
If WordPress version doesn't support custom logo or no custom logo is set (or it is removed), display default/fallback logo.
So far, this is best code I have to work with:
<?php if ( function_exists( 'the_custom_logo' ) ) : ?>
<?php if ( has_custom_logo() ) : ?>
<?php the_custom_logo(); ?>
<?php else : ?>
<h1 class="site-title"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/logo.png" alt="<?php bloginfo( 'name' ); ?>" width="100" height="50" /></h1>
<?php endif; ?>
<?php else : ?>
<h1 class="site-title"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/logo.png" alt="<?php bloginfo( 'name' ); ?>" width="100" height="50" /></h1>
<?php endif; ?>
Is there a cleaner or more efficient way of doing this without repeating the code for the fallback image twice?
Thanks but I think I found a better solution:
<?php if ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) : ?>
<?php the_custom_logo(); ?>
<?php else : ?>
<h1 class="site-title"><img src="<?php echo get_stylesheet_directory_uri(); ?>/images/logo.png" alt="<?php bloginfo( 'name' ); ?>" width="100" height="50" /></h1>
<?php endif; ?>
You can test both function_exist() and has_custom_logo() in same if condition for getting a single else condition.
$logo = ( ( function_exists( 'the_custom_logo' ) ) && ( has_custom_logo() ) ) ? the_custom_logo() : null;
if ($logo) {
echo $logo;
} else {
echo '<h1 class="site-title"><img src="' . get_stylesheet_directory_uri() . '/images/logo.png" alt="' . bloginfo( 'name' ) . '" width="100" height="50" /></h1>';
}
i'm a beginner in code and even if people have probably answered this question i don't know how to implement it in my case...
in my wordpress, i have a woocommerce integrated and i would like to display a different header logo then the home page.
i have found the place where it is called but i dont know how to implement it correctly and not scrap all the code.
i would probably want something like this
<?php if (isset($class) && $class == 'woocommerce'): ?>
<img src="images/logo-with-white-text" />
<?php else: ?>
<img src="images/logo-with-dark-text" />
<?php endif; ?>
implemented in this code from my theme
<!-- START LOGO -->
<div id="logo" class="<?php echo $width_tagline ?>" >
<?php
if( yit_get_option( 'header-custom-logo' ) == 'yes' && yit_get_option( 'header-custom-logo-image' ) != '' ) : ?>
<a id="logo-img" href="<?php echo home_url() ?>" title="<?php bloginfo( 'name' ) ?>">
<?php $size = #getimagesize(yit_get_option( 'header-custom-logo-image' )); ?>
<img class="no-dark" src="<?php echo yit_ssl_url( yit_get_option( 'header-custom-logo-image' ) ) ?>" <?php if( yit_get_option( 'logo-retina-url' ) ): ?>data-at2x="<?php echo yit_ssl_url( yit_get_option( 'logo-retina-url' ) ) ?>"<?php endif ?>title="<?php bloginfo( 'name' ) ?>" alt="<?php bloginfo( 'name' ) ?>" <?php if( !empty($size) && isset($size[3] ) ) echo $size[3] ?> />
<?php if ( 'yes' == YIT_Layout()->enable_dark_header ) : ?>
<?php $size = #getimagesize(yit_get_option( 'header-dark-custom-logo-image' )); ?>
<img class="only-dark" src="<?php echo yit_ssl_url( yit_get_option( 'header-dark-custom-logo-image' ) ) ?>" title="<?php bloginfo( 'name' ) ?>" alt="<?php bloginfo( 'name' ) ?>" <?php if( !empty($size) && isset($size[3] ) ) echo $size[3] ?> />
<?php endif; ?>
</a>
<?php else : ?>
<a id="textual" href="<?php echo home_url() ?>" title="<?php echo str_replace( array( '[', ']' ), '', bloginfo( 'name' ) ) ?>">
<?php echo yit_decode_title( get_bloginfo( 'name' ) ) ?>
</a>
<?php endif ?>
<?php
if( yit_get_option( 'header-logo-tagline' ) == 'yes' ):
$class = array();
if ( strpos( get_bloginfo( 'description' ), '|') ) $class[] = 'multiline';
if ( yit_get_option('header-logo-tagline-mobile') == 'no' ) $class[] = 'hidden-xs';
$class = ! empty( $class ) ? ' class="' . implode( $class, ' ' ) . '"' : '';
?>
<?php yit_string( "<p id='tagline'{$class}>", yit_decode_title( get_bloginfo( 'description' ) ), '</p>' );?>
<?php endif ?>
</div>
<!-- END LOGO -->
I hope someone will be kind enough to help me out on this one!
Thanks in advance
My way doing this
<a href="<?php echo home_url(); ?>" class="logo_link">
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/logo.png" data-src="<?php echo get_template_directory_uri(); ?>/assets/images/logo-wc.png" alt="" class="logo">
</a>
<script>
$( document ).ready(function() {
if($('body').hasClass('woocommerce')) {
$('.logo_link img').attr('src', $(this).data('src'));
}
});
</script>
If woocommerce is installed and activated you can do this
<?php if(is_woocommerce()){ ?>
<img src="images/logo-with-white-text" />
<?php }else{ ?>
<img src="images/logo-with-white-text" />
<?php } ?>
I don't understand how I get an default image from theme folder when Option Tree logo is not selected.
<div id="logo-section">
<?php if ( function_exists( 'ot_get_option' ) ) : ?>
<?php $logo = ot_get_option( 'pp_logo_upload' ); ?>
<a href="<?php bloginfo('url'); ?>">
<img src="<?php echo $logo; ?>" class="logo" />
</a>
<?php endif; ?>
Option Tree accepts a second parameter for ot_get_option that is the default in case no option is saved.
<?php if ( function_exists( 'ot_get_option' ) && ( $logo = ot_get_option( 'pp_logo_upload', 'some-image.png' ) ) != '' ){ ?>
<div id="logo-section">
<img src="<?php echo esc_attr( $logo ); ?>" class="logo" />
</div>
<?php } ?>
I trying to display a different logo for a page in a wordpress site.
I have the default Logo theme, and i want to insert a different logo for a page.
here is the code that manage the logo display in the theme file:
<a href="<?php echo home_url() ?>/" title="<?php bloginfo( 'name' ) ?>" class="logo <?php if ( empty( $logo ) || $logo_type === 'site-title' ) echo 'text-logo' //xss ok ?>" style="min-width:<?php echo $logo_size['width'] / 2 // xss ok ?>px"><?php
if ( $logo && $logo_type === 'image' ):
?>
<img src="<?php echo esc_url( $logo ) ?> " alt="<?php bloginfo( 'name' )?>" class="normal-logo" height="<?php if ( ! empty( $logo_size['height'] ) ) echo $logo_size['height']/2 // xss ok ?>" style="<?php echo esc_attr( $logo_style ) ?>"/>
<?php
else:
bloginfo( 'name' );
endif;
?
I want to insert a condtional tags function after the img src= like this:
else if(is_page('Name-Page')){
echo '<img src="images/logo-for-page.png" />';
}
I try to insert the funcion directly after the img src but t doesn't work.
Any idea? thank you
<img src="<?php echo ( is_page('Name-Page') ? "images/logo-for-page.png" : esc_url( $logo ) ) ?>" ....