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.

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).

Ideas?

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
add comment

2 Answers 2

up vote 1 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') );
        exit;
    }

}
share|improve this answer
add comment

Alright, found one solution, although not that elegant.

function load_if_mobile() {
    if ( wp_is_mobile() ) {?>
    <script>
        window.location = '/wp-admin/edit.php';
    </script><?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
add comment

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.