How to apply a function to the title of a teaser made with display suite? I'm pretty new to functions and PHP (so please forgive my terminology) but here's what I would like to do:

Background

My homepage contains a view displaying various content type teasers. I would like to truncate the title of an article teaser (a custom teaser created with display suite) to 48 characters.

Action taken so far

If I add the following code to my subtheme's template.php file, nothing happens:

function THEMENAME_preprocess_node(&amp;$variables) {
     if ($variables['type'] == 'article' &amp;&amp; $variables['view_mode'] == 'teaser') {
     $variables['title'] = truncate_utf8($variables['title'], 48, TRUE, TRUE);
   }
}


However, if I add this other variation of the code (i.e. applying to all teasers, not just article teasers) the titles of some teasers are indeed shortened:

function eunic_global_preprocess_node(&amp;$variables) {
if ($variables['teaser']) {
    $variables['title'] = truncate_utf8($variables['title'], 48, TRUE, TRUE);
   }
}


Conclusion &amp; Question

I think the problem is to do with the fact that some teasers have been created using the Display Suite module while others use more or less the default teaser.

So my question is - how do I 'refer' to the title of a teaser made with display suite in order to apply the truncate_utf8 function? Fingers crossed there's a way to do it...

Thanks
A~
If you added the title as a field in Display Suite, I'd recommend you look at the field functions of Display Suite.

You may use a Code field, but I'd discourage that. 

Rather remove the title from the display, then add the truncated title as a new field in the preprocess function, ie:

$variables['new_title'] = truncate_utf8($variables['title'], 48, TRUE, TRUE);


Then add a new preprocess field to display suite, using the exact same name as the new field, ie:

new_title


You can then place this new field in Display Suite.