I want to override/remove some HTML added to page_bottom by a Drupal module, using a second Drupal module.

I tried to use hook_page_alter but this appears to be run before hook_preprocess_html as I can't see the content that the first Drupal module inserts in the page variable at that point.

The only solution I've found at the moment is to use hook_process_html and remove the unwanted HTML from page_bottom using regex - at this point all page_bottom additions are merged into a single array value so I can't just unset the unwanted value. This seems very messy.

Edited to add, here's the preprocess hook from the original module:

function module_one_preprocess_html(&$variables) {
  $theme_variables = array(
    'var1' => $var1,
    'var2' => $var2,

  $variables['page']['page_bottom']['module_one'] = array(
    '#markup' => theme('module_one', $theme_variables),

Check out John Albin's graph for the different preprocess functions you can use http://john.albin.net/sites/default/files/theme-system.png (from http://john.albin.net/drupal/arrays-of-doom) for a "complete" reference of what could be happening.

Without looking to the code to see if you've got another alternative (such as field_attach or another render option), I'd go for hook_process, that's always going to go after preprocess. If it's a theme function, you can use hook_theme_registry_alter and override the theme callback.

Now an answer after seeing the code.

If you want, you can stick with hook_process_html, but as you said, the content is already rendered and is way harder to remove.

One thing you can do is to increase the weight of your second module in comparison with the one that has the preprocess that you want to override, that way, you could do a preprocess_html and it always will come after the other one.

A couple of ways of doing this, one is on hook_install as you can see in this doc page: https://www.drupal.org/node/110238

  $weight = db_select('system', 's')
              ->fields('s', array('weight'))
              ->condition('name', '[the_other_module_name]', '=')
    ->fields(array('weight' => $weight +1))
    ->condition('name', '[your_module_name]', '=')

If you can't or don't want to do this, there are a couple of modules that can help you: Modules weight and Util

  • Thanks for your response, I've added the preprocessor from the original module to my original question. – Accelebrate Jun 19 '14 at 9:06
  • Added a more adequate answer above. – pcambra Jun 19 '14 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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