Changing value of a field before rendering in Drupal 7 I am trying to change the value of a field. I need to add a dynamic class on-the-fly, based on some complext context, and I need to warp the text value with the span-class-stuff. But I haven't been able to alter the value, even if I am able to read it. I use MYTEMPLATE_preprocess_page(&amp;$variables, $hook), MYTEMPLATE_preprocess_field..., even some hooks in my modules, but to no avail. I am unable to change it. What would be the best and effective approach?
I suppose you're not actually trying to change the value of a field – but instead change one of its attributes? It would probably be useful to see how you're trying to rewrite the classes inside those theme functions so far. Basically that should already be the right location to do this. 

I recently just had a very similar problem, wanting to rewrite classes of a node. I know it's not exactly what you're asking – but the approach should be very similar. Inside your preprocess funtion first you should extract the already existing classes for later use:

$variables['classes_array'][] = drupal_html_class('node-' . $node-&gt;type);


Then you could add classes to the classes_array according to your conditions:

if ($variables['promote']) {
    $variables['classes_array'][] = 'node-promoted';
}


Find full example code and further details on this page or also over here.