4

Target: Drupal 7 Sub-Theme Development
I don't want to override whole template.php file. I just want to override single function of template.php file.

5

It really depends on the type of function:

  • If it's a theme function (theme_username()) you could simply re-declare the function with your sub-themes name (SUBTHEME_username()).

  • If it's a preprocess function, you can have your own version of the preprocess in your sub-theme, but IIRC the parent theme preprocess will still be invoked.

  • If it's a your own function (not a standard HOOK based function), then you would have to put some of your own logic to allow other themes to overwrite it.

Maybe provide some more information on the function in question so that someone can give you a more specific answer.

  • I'm interested to alter/add THEME_html_head_alter() function. Please, help. Add another answer (so that I could accept it as best answer). – user931 Mar 4 '11 at 12:57
1

You can use hook_html_head_alter() to alter XHTML HEAD tags before they are rendered by drupal_get_html_head().

function mytheme_html_head_alter(&$head_elements) {
  foreach ($head_elements as $key => $element) {
    if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {
      // I want a custom canonical URL.
      $head_elements[$key]['#attributes']['href'] = mymodule_canonical_url();
    }
  }
}

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.