Publish a message on facebook after having posted a comment

or should I create a plugin ? if it’s the case, why ?

Yes you should: Separation of concerns. A theme is the view of the application. As the facebook functionality is part of your application, it belongs into a plugin.

You have one large benefit from moving stuff into plugins: If you exchange your theme, you can easily switch themes without loosing the functionality and having to code all that again.

And always use hooks and (even better) filters to bring stuff into templates. Hooks like the_content, start_loop, end_loop and the_post are perfect for attaching plugin output to the view. And they’re present per default as core injects them into loops.

tech