4.6.x menu.inc menu_set_active_item($path = NULL)
4.7.x menu.inc menu_set_active_item($path = NULL)
5.x menu.inc menu_set_active_item($path = NULL)
6.x menu.inc menu_set_active_item($path)
7.x menu.inc menu_set_active_item($path)

Sets the active path, which determines which page is loaded.

Note that this may not have the desired effect unless invoked very early in the page load, such as during hook_boot(), or unless you call menu_execute_active_handler() to generate your page output.


$path: A Drupal path - not a path alias.

Related topics

1 call to menu_set_active_item()
user_page in modules/user/user.pages.inc
Page callback: Displays the user page.


includes/menu.inc, line 2351
API for the Drupal menu system.


function menu_set_active_item($path) {
  $_GET['q'] = $path;

  // Since the active item has changed, the active menu trail may also be out
  // of date.


Royce Kimmons’s picture

The parameters section suggests invoking the menu_set_active_item() function during hook_boot(), but this leads to an 'undefined function' error in my module. Is there another hook that can invoke menu_set_active_item() or drupal_access_denied() early on in the page load?

Specifically, I'm trying to layer on an additional, external security mechanism (fed from a non-Drupal cookie), and I want to be able to deny access to pages as early on as possible.

Madis’s picture

carvalhar’s picture

I'm using this function within my theme at template.php

function MYTHEME_preprocess_page(&$vars) {
		switch ($vars['node']->type) {
			case 'article':
//change MY_TRAIL for your Drupal path (can be aliased, don't need full path)
			case 'page':
mattjbondi’s picture

Thanks carvalhar! This saved me hours! Using this to set a menu item generated by hook_menu to active for a certain node type - thereby faking it as the parent...

iamkirkbater’s picture

Thanks for this.

Seldell’s picture

If you have something like :
"articles/myArticle" and you use the code above in order to have for example :
"/articles" active on your menu, this will change your arg(0) and (arg1) on corresponding nodes !

In my example, arg(0) will be "articles" and arg(1) will not exist.

If you use "menu_set_active_item" for your menus, you seems to kill the function which using arg(), like menu_get_object() which we generally use to get the $node in a block...
So be aware :(

Seldell’s picture

Me again. So like I said before, menu_set_active_item() is changing your "q=node/123" by "articles". So you don't have arg(0) = "node" and arg(1) = 123, but instead arg(0) = articles because of menu_set_active_item("articles").

So I really advise you to use instead menu_tree_set_path() like this :

        switch ($variables['node']->type) {
            case 'article':
            case 'other':

It will active the link "/articles" only in the menu "main-menu" and it will not change q=node/123, so you can use like usually arg() and menu_get_object(), or current_path(), etc ! :)