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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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