If add_action comes up undefined, you're trying to run it outside of your theme's core files - basically, it's running without any of the processing WordPress is supposed to do before hitting your custom functions. This should be in your theme's functions. php file or within a plugin, as Colin pointed out.