you can place your function in functions.php and attach an action hook . which will decide when to call your function. If you only want to hide content of the posts you can use this hook
add_action('the_content', 'yourcustomfunction')
or i would suggest this hook which will be called before your actually post query is run .
add_action('pre_get_posts', 'yourcustomfunction')
function yourcustomfunction () {
// YOUR CUSTOM CODE HERE
}
place this in your theme’s functions.php .