I need to replace template_preprocess_links with my own preprocess function and I can't find in the documentation how to replace a preprocess function entirely. Here is my current HOOK_theme implementation:

 * Implements hook_theme().
function my_module_theme($existing, $type, $theme, $path)
  return [
    'links' => [
      'variables' => [
        'links' => NULL,
        'raw_links' => NULL,
        'attributes' => NULL,
        'heading' => NULL
      'override preprocess functions' => TRUE

But even with override preprocess functions set to TRUE, the core template_preprocess_links is still called and pollute the output with rendered links.

How can I replace this preprocess function entirely?

1 Answer 1


hook_theme() is for new theme implementations, not altering the existing ones, and 'override preprocess functions' can be used just from themes.
The hook you need to implement is hook_theme_registry_alter().

This example code shows how to remove a preprocess function for a theme implementation.

function mymodule_theme_registry_alter(&$theme_registry) {
  // Kill the next/previous forum topic navigation links.
  foreach ($theme_registry['forum_topic_navigation']['preprocess functions'] as $key => $value) {
    if ($value == 'template_preprocess_forum_topic_navigation') {
      unset($theme_registry['forum_topic_navigation']['preprocess functions'][$key]);

Removing all the preprocess functions would just require a line like unset($theme_registry['forum_topic_navigation']['preprocess functions'].

The same is true for Drupal 7. (See the example code given in hook_theme_registry_alter() - Drupal 7.)

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.