0

I am creating a menu item using the following code.

$item = array(
'link_path' => 'node/custom',
'link_title' => 'Custom Title 001',
'menu_name' => 'menu-custom-menu', // Menu machine name, for example: main-menu
'weight' => 0,
'plid' => 0, // Parent menu item, 0 if menu item is on top level
'module' => 'menu',
);
menu_link_save($item);

I can see the entries is menu_links table, but can not see this menu item under the menu at 'admin/structure/menu/manage/menu-custom-menu'. What is wrong with my code?

Please note this path('node/custom' actually doesn't exist in Drupal System.

2
  • Where have you put this code? And have you cleared menu cache?
    – Mołot
    Aug 4, 2014 at 13:31
  • I am using a custom module. Using menu_cache_clear_all(); at the end of the code now. But it is not working. :( Aug 4, 2014 at 13:33

1 Answer 1

0

Please note this path('node/custom') actually doesn't exist in Drupal System.

Whenever we create using admin a menu it asks for a valid path otherwise it shows error of Url doesn't exist. So probably it enters the data in database directly but will not be listed in the admin unless it has a valid path assigned.

Please try by adding a page, e.g node/1 to the path and then try.

$item = array(
'link_path' => 'node/1',
'link_title' => 'Custom Title 001',
'menu_name' => 'menu-custom-menu', // Menu machine name, for example: main-menu
'weight' => 0,
'plid' => 0, // Parent menu item, 0 if menu item is on top level
'module' => 'menu',
);
menu_link_save($item);

and make sure node/1 exists in the system.

Hope it will help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.