https://drupal.org/documentation/customization/php-snippets – this is a great part of the drupal site that deals with the concept of inserting snippets of code into your site to do specific things.
https://drupal.org/node/23223 – This is a great article that deals with the mechanics of how to insert the code into your site.