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

Looking for a way to redirect the user from the dashboard straight to edit.php if wp_is_mobile() is true.

This is what I've tried:

function redirect_if_mobile() {
    $screen = get_current_screen();
    if($screen->base == 'dashboard') {
        if ( wp_is_mobile() ) {
            $url = admin_url( 'edit.php' );
            wp_redirect( $url );
add_action( 'admin_menu', 'redirect_if_mobile');

The problem is that get_current_screen() isn't defined in either admin_init or admin_menu (if you hook onto admin_head instead it's too late and headers have already been sent).


share|improve this question
You could use global $pagenow; if('index.php'==$pagenow)/* etc */. Also, Adminimize has the option to hide the Dashboard menu item and redirect to other page. – brasofilo Nov 12 '12 at 23:47
up vote 2 down vote accepted

The action you're looking for is auth_redirect, which is before the headers but still recognizes $pagenow to tell which page you're on:

add_action('auth_redirect', 'the_mobile_boot');
function the_mobile_boot() {
    global $pagenow;

    if ( $pagenow == 'index.php' && wp_is_mobile() ) {
        header( 'Location: ' . get_admin_url(null, 'edit.php') );

share|improve this answer

You can actually use the function you're using, you just need to use load-index.php (no need for globals if you don't need them):

add_action('load-index.php', function(){
    if(get_current_screen()->base == 'dashboard' && !wp_is_mobile())
share|improve this answer
Dude! I just upvoted and have no idea if this works, but looks fantastic. codex.wordpress.org/Plugin_API/Action_Reference/load-(page). Do you know what is available here ( meaning "plugins_loaded, init" actions )? – Nathan Powell Feb 3 at 4:02

Alright, found one solution, although not that elegant.

function load_if_mobile() {
    if ( wp_is_mobile() ) {?>
        window.location = '/wp-admin/edit.php';
add_action('admin_head-index.php', 'load_if_mobile');
share|improve this answer
And here, your original wp_redirect() works, ain't it? – brasofilo Nov 12 '12 at 23:48

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.