Skip to main content
deleted 68 characters in body; edited title
Source Link
Mołot
  • 21.9k
  • 8
  • 59
  • 112

How to create custom menu link wrapper function in drupalDrupal 7?

As you know default wrapper for menu item in drupalDrupal 7 can be modified via function theme_menu_link().

** theme is the name of theme

by overriding

theme_menu_link($variables) {} 

function we can modify the rendered html output of menu link but it will change all of menu items that their #theme attribute is set to this function. for example in main menu, each item has menu_link__main_menu value in it's #theme attribute.

Now I want to create a custom wrapper function in my theme.

I searched and I found I must create a function with structure like

theme_menu_link($variables) {}

and also I must REGISTER the function name in my theme.

For registration, I used function theme_theme() {}

function theme_theme() {return array('custom_menu_item_wrapper' => array());}

** theme is replaced by name of theme ** custom_menu_item_wrapper is the name of my function for wrapping operation

But I don't know, how should I define parameters in theme function registration because when custom_menu_item_wrapper($variables) function is called $variables is NULL

Please guide me.

Thanks a lot.

How create custom menu link wrapper function in drupal 7

As you know default wrapper for menu item in drupal 7 can be modified via function theme_menu_link().

** theme is the name of theme

by overriding

theme_menu_link($variables) {} 

function we can modify the rendered html output of menu link but it will change all of menu items that their #theme attribute is set to this function. for example in main menu, each item has menu_link__main_menu value in it's #theme attribute.

Now I want to create a custom wrapper function in my theme.

I searched and I found I must create a function with structure like

theme_menu_link($variables) {}

and also I must REGISTER the function name in my theme.

For registration, I used function theme_theme() {}

function theme_theme() {return array('custom_menu_item_wrapper' => array());}

** theme is replaced by name of theme ** custom_menu_item_wrapper is the name of my function for wrapping operation

But I don't know, how should I define parameters in theme function registration because when custom_menu_item_wrapper($variables) function is called $variables is NULL

Please guide me.

Thanks a lot.

How to create custom menu link wrapper function in Drupal 7?

As you know default wrapper for menu item in Drupal 7 can be modified via function theme_menu_link().

by overriding

theme_menu_link($variables) {} 

function we can modify the rendered html output of menu link but it will change all of menu items that their #theme attribute is set to this function. for example in main menu, each item has menu_link__main_menu value in it's #theme attribute.

Now I want to create a custom wrapper function in my theme.

I searched and I found I must create a function with structure like

theme_menu_link($variables) {}

and also I must REGISTER the function name in my theme.

For registration, I used function theme_theme() {}

function theme_theme() {return array('custom_menu_item_wrapper' => array());}

** theme is replaced by name of theme ** custom_menu_item_wrapper is the name of my function for wrapping operation

But I don't know, how should I define parameters in theme function registration because when custom_menu_item_wrapper($variables) function is called $variables is NULL

Source Link
Mehrdad201
  • 1.3k
  • 3
  • 19
  • 34

How create custom menu link wrapper function in drupal 7

As you know default wrapper for menu item in drupal 7 can be modified via function theme_menu_link().

** theme is the name of theme

by overriding

theme_menu_link($variables) {} 

function we can modify the rendered html output of menu link but it will change all of menu items that their #theme attribute is set to this function. for example in main menu, each item has menu_link__main_menu value in it's #theme attribute.

Now I want to create a custom wrapper function in my theme.

I searched and I found I must create a function with structure like

theme_menu_link($variables) {}

and also I must REGISTER the function name in my theme.

For registration, I used function theme_theme() {}

function theme_theme() {return array('custom_menu_item_wrapper' => array());}

** theme is replaced by name of theme ** custom_menu_item_wrapper is the name of my function for wrapping operation

But I don't know, how should I define parameters in theme function registration because when custom_menu_item_wrapper($variables) function is called $variables is NULL

Please guide me.

Thanks a lot.