Drupal – Clean up exisiting code that converts text into an image

I’ve created the following snippet of code within a custom content.tpl.php template

<?php
$field = field_get_items('node', $node, 'field_youtube_video_link');

if(!empty($field)): ?>
  
field_youtube_video_link['und'][0]['url'].">".$img."";?>
<?php endif; ?>

I’m really wanting to clean this up and rather than do all of this in the content-type.tpl.php I would prefer to do this through a preprocess hook and then create a custom theme template for it, but I’m unsure of how to achieve this?


Source: stackoverflow-php