WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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


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.