• I want the header image to display only mobile devices. I have my logo in the admin bar, which is always visible, so the header image is unnecessary on the desktop version, but it disappears on mobile devices. The header logo does show up, and displays quite nicely, so I’d like it to show only on mobile.

    Unless there’s a way to force the admin bar to show the logo on mobile, and display nicely. Either way is fine by me, so long as only one displays, and it looks decent.

    Any ideas?

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • This should get you started, place the code inside the style.css in your child theme.

    Two options…

    Option 1: Set the header-image container to display none on the desktop.

    @media screen and (min-width: 61.5625em) {
    	.header-image {
        		display: none;
    	}
    }

    Option 2: Set the image in the header-image container to display none on the desktop. This leaves the header-image container visible, and only hides the image.

    @media screen and (min-width: 61.5625em) {
    	.header-image img {
        		display: none;
    	}
    }
    Thread Starter skunkgrunt

    (@skunkgrunt)

    Thank you so much! I’ll keep this info for the next time I need it, but for now, I managed to achieve it by modifying the header.php file with the

    ( wp_is_mobile() )

    function.
    So my header file now looks like this:

    <?php if ( wp_is_mobile() ) : ?>
    
    			<?php if ( get_header_image() ) : ?>
    				<?php
    					/**
    					 * Filter the default twentysixteen custom header sizes attribute.
    					 *
    					 * @since Twenty Sixteen 1.0
    					 *
    					 * @param string $custom_header_sizes sizes attribute
    					 * for Custom Header. Default '(max-width: 709px) 85vw,
    					 * (max-width: 909px) 81vw, (max-width: 1362px) 88vw, 1200px'.
    					 */
    					$custom_header_sizes = apply_filters( 'twentysixteen_custom_header_sizes', '(max-width: 709px) 85vw, (max-width: 909px) 81vw, (max-width: 1362px) 88vw, 1200px' );
    				?>
    
    				<div class="header-image">
    					<a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home">
    						<img src="<?php header_image(); ?>" srcset="<?php echo esc_attr( wp_get_attachment_image_srcset( get_custom_header()->attachment_id ) ); ?>" sizes="<?php echo esc_attr( $custom_header_sizes ); ?>" width="<?php echo esc_attr( get_custom_header()->width ); ?>" height="<?php echo esc_attr( get_custom_header()->height ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>">
    					</a>
    				</div><!-- .header-image -->
    			<?php endif; // End header image check. ?>
                            <?php endif; // Mobile only header. ?>

    So I wrapped the entire header image check in the <?php if ( wp_is_mobile() ) : ?>
    Is this an acceptable way of doing this? Or is the CSS version you supplied a better way?

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Header Image only on mobile’ is closed to new replies.