Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Essentially is there a way to use a function in functions.php to turn the <body> tag into <body class="mobile">? I have code that recognizes mobile devices but right now it's set up to load a mobile.php page include(STYLESHEETPATH."/mobile.php");, which isn't quite what I want.

I've tried all sorts of mobile site plugins like WP mobile, mobify, etc. None of them work the way I want and I'd rather not mess with that anymore. Please don't suggest that.

I know this is kind of a newbie question but I can't find any info on it anywhere. Thanks for your time.

share|improve this question

1 Answer 1

The code below works, basically it adds your class to the wordpress body_class() array..

add_filter('body_class','my_class_names');
function my_class_names($classes) {
    // add 'class-name' to the $classes array
    $classes[] = 'mobile';
    // return the $classes array
    return $classes;
}

You can read more on this on the WP codex here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.