Add code inside specific wordpress standard function

It depends what you want to do.

If you look into the function definition, you’ll notice some do_action():

For example:

do_action( 'delete_attachment', $post_id );
do_action( 'delete_post', $post_id );
do_action( 'deleted_post', $post_id );

These are points, called hooks in WordPress, where you can actually run your stuff. Hooks will help you to modify the core behaviour without modifying the WordPress core itself.

Let’s assume you want to hook into the code before the attachment is deleted, you can then use add_action('delete_attachement', 'yourfunction'); in your plugin or theme’s functions.php to run any code you want.

For example:

add_action('delete_attachement', 'yourfunction');

function yourfunction( $post_id ){
  echo 'sample';
  die;
}