I am using the following preprocess in my template.php

function paddle_admin_preprocess_menu_block_wrapper(&$variables) {
  if ($variables['delta'] === 'management_level_2') {
    $variables['classes_array'][] = 'max-width';

It works as intended, it adds a class when the delta equals this string..

I am trying to modify another other entry of the classes_array array in order to make the classname more semantic. How would I go for that? (so replace an entry instead of add)

ps: I figured it can be as easy as:

$variables['classes_array'][1] = $variables['delta']; 

but I am wondering whether the array indexes can change (from the ones I see with devel themer)

1 Answer 1


Search for the key of the value you want to replace and then modify it. It's that simple.

function paddle_admin_preprocess_menu_block_wrapper(&$variables) {
  if ($variables['delta'] === 'management_level_2') {
    // Search for the key
    $key = array_search('class_to_be_replaced', $variables['classes_array']);

    // If class was found, replace it
    if ($key !== FALSE) {
        $variables['classes_array'][$key] = 'class_that_replaces';
  • If I just did $variables['classes_array'][1] = $variables['delta']; (I had a look with the devel themer and I know the one I'm trying to change is on the [1] location) would it be a safe thing to do? PS: your solution has one tiny issue: this class name has a variable part so I can't make a static string about it Commented Apr 6, 2013 at 17:49
  • 1
    If you are sure that no other modules will modify the classes array, then yes. Personally I would go with a more safe solution by searching for the key. If your class name is a variable, you can replace the string by it. You can also concatenate a string with a variable.
    – Lauri
    Commented Apr 6, 2013 at 17:52
  • If you enable or disable modules, then the index may change. Searching is safest.
    – mpdonadio
    Commented Apr 6, 2013 at 18:55

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.