Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect from edit.php to different page in wordpress backend

Trying to setup a redirect for Wordpress backend. I have used this code:

function redirected_admin_pages(){
    global $pagenow;

    if($pagenow == 'edit.php'){
       wp_redirect('edit.php?post_status=publish&post_type=post');
       exit;
    }
}
add_action('admin_init', array($this, 'redirected_admin_pages'));

I based it on the answer here https://wordpress.stackexchange.com/questions/52114/admin-page-redirect

For some reason I cant get it work. What am I doing wrong?

like image 431
user1721230 Avatar asked Mar 25 '26 20:03

user1721230


1 Answers

Well I got there in the end with a login redirect, see function below:

add_action( 'admin_menu', 'name_changing_thing' );

function name_changing_thing() {
  global $submenu;

  foreach( $submenu['edit.php'] as $key => $value )
  {
    if( in_array( 'edit.php', $value ) )
    {
        $submenu['edit.php'][ $key ][2] = 'edit.php?post_status=publish&post_type=post';
    }
  }
  }

Thank you to anyone who looked.

like image 61
user1721230 Avatar answered Mar 28 '26 15:03

user1721230



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!