How do i check if the current page is in the admin section of drupal?. I want to display a login form in some pages from the main menu but the login page is displayed in the block selection menu .Please suggest a solution ..
For Drupal 7 you can use path_is_admin() .
if (path_is_admin(current_path())) {
// Do stuff.
}
For Drupal 8 isAdminRoute()
$is_admin = \Drupal::service('router.admin_context')->isAdminRoute();
if ($is_admin) {
// Do stuff.
}
I don't fully understand your end goal, but here are two answers to your question:
1) if (arg(0) == 'admin') { ... }
will indicate if someone is in the admin section, since the entire admin section has paths prefixed with admin/
2) At admin/settings/admin/theme you can select a separate theme for the admin section, and then you'll know someone is in admin when that theme is loading rather than the main theme.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With