How to use custom function in posts and pages templates

I want to add a custom function to get related posts into my wp theme.

I have added this function code to my theme functions.php file but it will not work:

I’m calling the function in this way:

How I can fix this?