0

How to replace two classnames by writing a function in template.php

The two classnames given are:

comment-add 

and

comment-comments
0

Generally this is a matter of figuring out which preprocess function or functions are setting those classes and then implementing those preprocess functions within your own theme and modifying the $variables['classes_array'] variable to meet your needs.

Without knowing what theme you're using as a base theme I can't say for sure how this is being done. But using the following steps you should be able to figure it out.

  1. Figure out which template file (*.tpl.php) file contains the markup where the classes are being printed out, and note the name of this file. Example, 'comment-wrapper.tpl.php'.

  2. Working backwards up the chain you should be able to find the preprocess function that's setting these classes.

    • YOURTHEME_comment_wrapper_preprocess()
    • BASETHEME_comment_wrapper_preprocess()
    • template_comment_wrapper_preprocess()

This will at least confirm that you're on the right track, and allow you to see in what context those classes are set and what other classes may be set.

  1. Implement HOOK_comment_wrapper_preprocess() in your own theme. (Comment wrapper being the example here, you'll need to know the appropriate template file that's being used to know which preprocess function to implement.)

  2. Modify the $variables array inside your template file to change the classes.

Here's some additional information about preprocess functions: https://www.drupal.org/node/223430

| improve this answer | |

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.