function drupal_is_front_page

You are here

7 path.inc drupal_is_front_page()
4.7 path.inc drupal_is_front_page()
5 path.inc drupal_is_front_page()
6 path.inc drupal_is_front_page()
8 path.inc drupal_is_front_page()

Check if the current page is the front page.

Return value

Boolean value: TRUE if the current page is the front page; FALSE if otherwise.

10 calls to drupal_is_front_page()
hook_init in modules/system/system.api.php
Perform setup tasks for non-cached page requests.
hook_menu_breadcrumb_alter in modules/system/system.api.php
Alter links in the active trail before it is rendered as the breadcrumb.
l in includes/common.inc
Formats an internal or external URL link as an HTML anchor tag.
locale_block_view in modules/locale/locale.module
Implements hook_block_view().
menu_get_active_breadcrumb in includes/menu.inc
Gets the breadcrumb for the current page, as determined by the active trail.

... See full list

File

includes/path.inc, line 284
Functions to handle paths in Drupal, including path aliasing.

Code

function drupal_is_front_page() {
  // Use the advanced drupal_static() pattern, since this is called very often.
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['is_front_page'] = &drupal_static(__FUNCTION__);
  }
  $is_front_page = &$drupal_static_fast['is_front_page'];

  if (!isset($is_front_page)) {
    // As drupal_path_initialize updates $_GET['q'] with the 'site_frontpage' path,
    // we can check it against the 'site_frontpage' variable.
    $is_front_page = ($_GET['q'] == variable_get('site_frontpage', 'node'));
  }

  return $is_front_page;
}

Comments

Just a quick heads up. When hook_boot is fired, this function may not be available.

Why this function is not working in the hook_views_query_alter function?

This function sucks.
I used it in hook_init() and it returns TRUE on cron.php call! Spent several hours to debug that.

I just reported a core issue about its strange behaviour when run in drush or cron context: https://drupal.org/node/2221565