Filters should return, not echo.
function my_content( $content ) {
// Something something
$content="my content";
return $content;
}
add_filter( 'the_content', 'my_content' );
You can echo, but you’ll need output buffering, like this:
function my_content( $content ) {
// Something something
ob_start();
echo 'my content';
$content = ob_get_contents();
ob_end_clean();
return $content;
}
add_filter( 'the_content', 'my_content' );
Also, the reason you’re seeing your output in the head section is because the filter is likely being used somewhere in the head section, perhaps by some plugin, so be careful since you might be overriding something more than you’re hoping to.
Hope that helps.