Overriding hook_preprocess_html page contents set by a module 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(&amp;$variables) {
  $theme_variables = array(
    'var1' =&gt; $var1,
    'var2' =&gt; $var2,
  );

  $variables['page']['page_bottom']['module_one'] = array(
    '#markup' =&gt; 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')
              -&gt;fields('s', array('weight'))
              -&gt;condition('name', '[the_other_module_name]', '=')
              -&gt;execute()
              -&gt;fetchField();
  db_update('system')
    -&gt;fields(array('weight' =&gt; $weight +1))
    -&gt;condition('name', '[your_module_name]', '=')
    -&gt;execute();


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