Clean all markup of a field with "nomarkup" theme function

Public

Register theme function in your module or theme:

Get raw version
php
  1. /**
  2.  * Implements HOOK_theme().
  3.  */
  4. function YOUR_THEME_NAME_theme(){
  5. return array(
  6. 'nomarkup' => array (
  7. 'render element' => 'element',
  8. ),
  9. );
  10. }
Get raw version
php
  1. /**
  2.  * Cleans all markup of a field.
  3.  */
  4. function theme_nomarkup($variables) {
  5. $output = '';
  6. foreach ($variables['items'] as $delta => $item) {
  7. $output .= drupal_render($item);
  8. }
  9. return $output;
  10. }

Then you can use this theme function in your .tpl file to get clean content from a field:

Get raw version
php
  1. <?php
  2. $content['field_NAME']['#theme'] = "nomarkup";
  3. // Print a clean from markup field
  4. print render($content['field_NAME']);
  5. ?>