Skip to content

Commit

Permalink
Add basic mobile detection to <body> class
Browse files Browse the repository at this point in the history
Not too fancy, not too clever, but will add 'is-mobile' or 'is-not-mobile' additional class to body tag using WordPress wp_is_mobile() function.
  • Loading branch information
Jonnyauk committed Nov 23, 2015
1 parent 46ed9c8 commit 2f7942e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions wf-includes/wf-display-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ function wf_head_css_replace() {

/**
* @since 0.931
* @updated 1.2
* @updated 2.1
*
* @filter wflux_body_class_browser : Filter for the browser detection CSS class output
* @filter wflux_body_class_layout : Filter for Wonderflux layout description classes
Expand All @@ -409,6 +409,8 @@ function wf_body_tag(){
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
$browser = 'browser-';

$is_mobile = ( wp_is_mobile() ) ? ' is-mobile' : ' is-not-mobile';

switch (TRUE){
case $is_lynx: $browser .= 'lynx'; break;
case $is_gecko: $browser .= 'gecko'; break;
Expand All @@ -421,11 +423,11 @@ function wf_body_tag(){
default: $browser .= 'browser-not-defined'; break;
}

$this->head_classes[] = apply_filters( 'wflux_body_class_browser', $browser );
$this->head_classes[] = apply_filters( 'wflux_body_class_browser', esc_attr($browser . $is_mobile) );

// Setup additional layout classes
$layout_classes = array();
$layout_classes[] = ( $this->wfx_sidebar_1_display == 'Y' ) ? 'content-with-sidebar-1' : 'content-no-sidebar-1';
$layout_classes[] = ( $this->wfx_sidebar_1_display == 'Y' ) ? ' content-with-sidebar-1' : ' content-no-sidebar-1';
$layout_classes[] = ( $this->wfx_sidebar_1_display == 'Y' && $this->wfx_sidebar_primary_position == 'left' ) ? ' sidebar-1-left' : '';
$layout_classes[] = ( $this->wfx_sidebar_1_display == 'Y' && $this->wfx_sidebar_primary_position == 'right' ) ? ' sidebar-1-right' : '';
$layout_classes[] = ' width-'.$this->wfx_width;
Expand All @@ -439,7 +441,7 @@ function wf_body_tag(){
$this->head_classes[] = $layout_classes_str;

// Put it all together and filter body_class
add_filter( 'body_class', array($this, 'wf_body_tag_filter') );
add_filter( 'body_class', array($this, esc_attr('wf_body_tag_filter')) );

}

Expand Down

0 comments on commit 2f7942e

Please sign in to comment.