Add a new filter expression immediately after the <body>
tag. Like the following
<body <?php body_class(); ?>>
<?php echo apply_filters("immediately_after_body","");?>
Now in your functions.php add the filter hook like this
add_filter("immediately_after_body","my_function");
function my_function(){
//do your calculation
return "<h1>output from Filter Hook</h1>";
}
You can see the output immediately after <body>
tag. Use filters, they were built for a purpose 🙂