WordPress.org

Forums

conditional mobile tag only works sometimes (2 posts)

  1. gregfielding
    Member
    Posted 2 years ago #

    I'm having some trouble where my site only switches to the mobile version about half of the time. Otherwise it still shows the full site on mobile devices, which looks terrible.

    At first I thought it was a caching issue, but it's not.

    I'm using conditional mobile tags, as explained here: http://codex.wordpress.org/Function_Reference/wp_is_mobile

    The site is http://www.bayarearealestatetrends.com/

    I figure that there are either bugs with the condition, or I'm using it wrong somehow... but I can't figure out why it would show sometimes and not others.

    Here is an example of code I'm using to show a different header to mobile users. Am I doing this wrong?

    <?php if (wp_is_mobile() ) : ?>
    
                    <?php $header_image = get_header_image();
    		if ( ! empty( $header_image ) ) : ?>
    			<a href="http://www.bayarearealestatetrends.com"><img src="http://www.bayarearealestatetrends.com/wp-content/uploads/2013/01/logobaymobile.png" style="width:90%"></a>
    <?php endif; ?>
    <?php else : ?>
    
    		<?php $header_image = get_header_image();
    		if ( ! empty( $header_image ) ) : ?>
    			<a href="<?php echo esc_url( home_url( '/' ) ); ?>" style="background:#333; shadow-box:0px"><img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?> box-shadow="0px" height="<?php echo get_custom_header()->height; ?> alt="" /></a>
    		<?php endif; ?>
    <?php endif; ?>

    Thanks!

  2. gregfielding
    Member
    Posted 2 years ago #

    Just giving this one a polite bump... is anyone else having trouble with the wp_is_mobile conditional tag? Is there a better way to do it?

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic