Drupal 7 with Omega version 3 theme generates a username class for the article tag in the HTML code, something like :

class="node node-page node-published node-not-promoted node-not-sticky author-USERNAME odd clearfix".

I'd like to avoid having the username displayed in the code for security reasons.

After investigating, this comes from the code "omega_alpha_preprocess_node()" in the "sites/all/themes/omega/omega/template.php" where you find the following line:

"$vars['attributes_array']['class'][] = drupal_html_class('author-' . $vars['node']->name); "

I copied the code of "omega_alpha_preprocess_node()" to the "template.php" of my Omega subtheme, I renamed the "omega_alpha_preprocess_node()" to "MYTHEME_alpha_preprocess_node" and removed the line "$vars['attributes_array']['class']". Unfortunatly, it does not work.

As of today, the solution I found is to remove the line "$vars['attributes_array']['class']" from the initial Omega template.php file, which is not the best practice, but it works and the username output as a class of an article tag is no longer displayed.

Can someone help me find a more elegant solution, as I'm not a very experienced Omega developer and I need guidance? Thank you.


The theme function your trying to us is theme_preprocess_node, and you'r correct in replacing the Omega with [yourtheme].

The reason the function isn't getting called though is MYTHEME_alpha_preprocess_node should just be MYTHEME_preprocess_node. Alpha is part of the theme name, so if you remove it, the function should start working for you once you clear your cache.

EDIT ---------------------------------

Because drupal's template functions are still hooks, you can't just override the preprocess_node function, as omega's preprocess function is still going to run. However, what you can do is edit the $vars variable. Make sure you have the & in the param ( ie function (&$vars) ) so the vars is a reference.

From there, you should be able to modify the $vars['attributes_array']['class'] array and remove the unwanted class.

So if you put something like this in your code, that should get you close to where you might need to be.

function mytheme_preprocess_node (&$vars){
    $count = 0;
      foreach($vars['attributes_array']['class'] as $class){
        if(substr( $class, 0, 7 ) === "author-"){
        $count += 1; 

EDIT 2 ============================

When I say remove the class from the var, I mean you should just be able to unset the variable (I updated my code snippet to show it inside the preprocess function).

You don't need to copy the whole of the omega_alpha_preprocess_node. What you actually are doing when you define your own theme_preprocess_node function is your telling drupal you would like to modify the variables for the node before it processes it. Because your working from a subtheme, the parent theme is still going to run it's own preprocess functions. So that class will always be added via omega. However, because your subtheme's preprocess function is downstream, it will get the &$vars reference with that class already added to it. So instead of rewriting the function, all that is needed is to simply remove the class from the $vars variable that you received in your params.

| improve this answer | |
  • Hi Jance, here is what I did based on your input : 1. I pasted back the entire code of "omega_alpha_preprocess_node()" in the "template.php" of the omega/template.php file. 2. I copied the "omega_alpha_preprocess_node()" to the "template.php" of my Omega subtheme and renamed it to "MYTHEME_preprocess_node". 3. I removed the "$vars['attributes_array']['class'][] " line from the "MYTHEME_preprocess_node". 4. I clerared all caches. Unfortunatly, it still does not work and the username class for the article tag is displayed in the HTML code. What did I do wrong ? Thank you for your help. – FL26 Oct 9 '14 at 16:13
  • @FL26, see my edit. – Jance Oct 9 '14 at 16:38
  • Thanks for your answer. When you say "edit the $vars variable", in which line? What I did is simply remove the lines "// Add a class to allow styling based on the node author. $vars['attributes_array']['class'][] = drupal_html_class('author-' . $vars['node']->name);" from the function MYTHEME_preprocess_node(&$vars).I suppose this is above my competence in Omega development. Thank you again. – FL26 Oct 9 '14 at 16:46
  • @FL26, I updated my answer again, but the basic thing that's going on is the preprocess function is giving you the chance to modify the node &$vars before they are processed. Your not overriding any functions, rather adding your own logic. You can't just copy the function and remove the line you don't want (because the parent theme's function is still going to run) rather, you need to remove the class that you don't want from $vars when your function runs. – Jance Oct 9 '14 at 17:58
  • Thank you Jance, your explaination is cristal clear. I added your snippet code to the template.php file of my subtheme and it worked perfectly. Thanks to you, I now better understand how a theme and its subtheme work. FYI, in your snippet code, (&&vars) should be replaced by (&$vars). Thought you'd like to know. – FL26 Oct 10 '14 at 7:56

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.