Referring to my question about the removal of "Add new comment" link from the book page links area, is there a way to remove the code with the help of hooks. I am new to implementing hooks. I have found the solution to the problem, but I need a better way to implement it(maybe by hooks, idk).

I did face a similar problem when I had to comment out the print $tree from the core book module's book-navigation.tpl.php, as it was printing the tree at the bottom of every node, and I didn't want it that way. I used the tree navigation block in my sidebar to navigate through the tree structure. Is there a quick way to do this?

  • The question that you linked to has an accepted answer that involves using a hook. Your question is confusing. Are you looking for a generic hook that can be used to remove any code from any module?
    – sheena_d
    Commented May 7, 2012 at 13:31
  • @sheena_d The answer did not solve my question(shouldn't have accepted it). I want the exact thing which you say. I'm new to hooks, and have tried and run numerous hooks, but couldn't do it.
    – AjitS
    Commented May 7, 2012 at 13:39
  • There isn't one generic hook that can alter anything. Modules can create their own hooks that can be used to modify specific pieces of that module's functionality. api.drupal.org is a resource for searching hooks included in the core modules, and most modules include a module_name.api.php file which includes documentation for all of the "hookable" functions within that module.
    – sheena_d
    Commented May 7, 2012 at 13:58

2 Answers 2


1) The suggested hook_link_alter() (in your linked question) does not exist in Drupal 7 so it doesn't work like you already found out. On the API page there's hook_node_view_alter() being mentioned which can be used instead. You can implement this specific hook both in a module and your theme's template.php file. To unset the comment link the following should work (updated based on the comment by Ajit):

function myThemeOrModule_node_view_alter(&$build) {
  if ($build['#node']->type == 'book') {

If it's not quite right you can try (in your development environment) finding out what to unset by adding the following line inside the function: drupal_set_message('<pre>'.var_export($build['links'], TRUE).'</pre>'); (until you have a better tool available).

2) Overriding template files is handled like paul-m already mentioned by creating a copy of the necessary tpl.php file inside your theme folder and doing all the changes there.

3) If you end up needing to override theme functions then you should create a copy of it inside your theme's template.php file where you can modify it.

Don't forget to clear the caches after adding a new function or template.

  • 1
    thank you so much :-) the hook worked fine with the modification unset($build['links']['comment']['#links']['comment-add']); I also checked to see some of the hooks on API page of Drupal. Real exciting this hook stuff is :-) Thank you again for the answer.
    – AjitS
    Commented May 10, 2012 at 7:16
  • Yeah, hooks help a lot in tailoring Drupal to fit different requirements/needs. Glad the answer was useful and thanks for mentioning the correct array element to unset the comment link (makes things easier for possible future visitors) :)
    – Madis
    Commented May 10, 2012 at 17:10

To solve the print $tree problem, you'd create a new book-navigation.tpl.php template file that doesn't print the $tree. You'd do this in your own theme, which could easily be a subtheme of whichever one you're using.

As for the previous question, md2 got it right. Implement this non-theme hook by creating a module. It's not that hard. The Examples project might help you a little, though it doesn't directly address this issue.

  • thank you for the reply. The actual problem is I was trying to implement Drupal 6 hook there and so it wasn't executing. I did found a solution(thanks to Dooshta), in the answer above
    – AjitS
    Commented May 10, 2012 at 7:18

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.