How can i add simple code in only in posts by function.php

You can perform simple check to make sure, the post type is post; before executing actual code.

For example:

add_action('wp_head', 'load_custom_style_for_posts');
function load_custom_style_for_posts(){

   global $post_type;

   if( 'post' == $post_type ){
      echo "<style>blahblah</style>";
   }

};

Place this code inside functions.php

Hope it helps! 🙂