I wish to conditionally add an item to a menu. I have a custom module and a menu called "links". How would I add an item to a menu in my module code?
You need to implement hook_menu in your module. Example:
<?php
function mymodule_menu() {
$items['mymodule/links'] = array(
'title' => 'Links',
'page callback' => 'mymodule_links_page',
'access arguments' => array('access content'),
'type' => MENU_SUGGESTED_ITEM,
);
return $items;
}
?>
The 'type' => MENU_SUGGESTED_ITEM, part makes it optional, so it can be enabled by the end user - is that what you meant with "conditionally"? If not, please explain what kind of "conditionally" you're looking for.
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