如何向每个重定向添加不同的重定向
如果elseif elseif像这样:
if ( condition 1 ) {
// do something
} elseif ( condition 2 ) {
// do something else
} elseif ( condition 3 ) {
// do something else
}
假设您创建了三个顶级管理菜单项:
add_menu_page( \'Slider Menu\', \'Slider\', \'manage_options\', \'page_slug\', \'function\', \'dashicons-images-alt2\', 6 );
add_menu_page( \'Page Title\', \'Menu Title\', \'manage_options\', \'page_slug2\', \'function\' );
add_menu_page( \'Page Title 2\', \'Menu Title 2\', \'manage_options\', \'page_slug3\', \'function\' );
然后你的如果elseif elseif看起来像这样:
// For the "Slider" menu.
if ( $menu_redirect == \'page_slug\' ) {
wp_safe_redirect( admin_url( \'post.php?post=1883&action=elementor\' ) );
exit();
// For the "Menu Title" menu.
} elseif ( $menu_redirect == \'page_slug2\' ) {
wp_safe_redirect( \'URL here\' );
exit();
// For the "Menu Title 2" menu.
} elseif ( $menu_redirect == \'page_slug3\' ) {
wp_safe_redirect( \'URL here\' );
exit();
}
顺便说一句,我想你应该使用
admin_url()
用于获取管理页面的URL。=)