Skip to:
Content
Pages
Categories
Search
Top
Bottom

Make some pages templates conditional on mobile or not

  • Avatar of valuser
    valuser
    Participant

    @valuser

    Probably more appropriate for WP forums.

    Any guidance on how to make full page template conditional for some pages when wp_is_mobile() much appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Well that function returns true or false so probably easiest way to use it is as a check on whether or not to enqueue a stylesheet specifically for media queries below 320px or something like that, but then again you could simply use a media query in the first place  and add any full width rules under it.

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    I use this on my site to show a different single.php. I have a folder mobile in my theme folder with my mobile templates. I copied single.php, removed the get_sidebar and then added css when on mobile to style it better. This code works in functions.php.

    `function mobile_filter_wp_template( $template ) {

    $overridden_template =  dirname( __FILE__ ) . ‘/mobile/mobile-single.php’ ;

    if ( is_single() && wp_is_mobile() ) {

    return load_template( $overridden_template );

    } else {

    return $template;

    }

    }

    add_filter( ‘template_include’, ‘mobile_filter_wp_template’, 10, 2 );`

     

    `function mobile_style() {

    if ( is_single() && wp_is_mobile() ) {

    echo ”

    <style>

    body {

    width: 100%;

    }

    </style>”;

    }

    }

    add_action(‘wp_head’, ‘mobile_style’);`

     

    Use WP is_page to set conditions to specific pages http://codex.wordpress.org/Function_Reference/is_page

    Avatar of valuser
    valuser
    Participant

    @valuser

    Thanks @hugo

    Thats what has to be done !

    I’ll just have to figure out how!

    Thanks @modemlooper.

    I think i did as per your advice.

    added

    && is_page(‘mixxed’) to each if statement.

    mixed is the name of the page

    redid all quotes.

    but

    white screen.

    tried replacing body with div#content .padder

    still white screen.

    The template panel was set at default as that would be the template for desktops ?

    The Mobile Single template appears in template panel but also gives white screen.

    I did a template with index.php as @hugo suggested in another topic and that does show full-width.

    removed sidebar call and changed padder to full-width.padder and

    div#content .full-width-padder {
    width: 95%;
    }

    it’s just to make it conditional for certain pages and mobile/tablet.

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    the formatting on here sucks when you paste code so that might be issue if you cut and paste, i use that exact code on modemlooper.me so I know it works. Are you trying to make a buddypress template full width? might need to adjust code

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    make sure its in functions.php if you place code elsewhere the the link to overriden_template has to be changed

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.