You can define your own custom functions in PHP just like you would in JavaScript. Here’s your code example rewritten using a function:
$page = get_page_by_title('Excerpts Showreel'); <-- This piece of code will change
// the code below will never change.
function get_my_content( $page ) {
$my_id = $page;
$post_id = get_post($my_id, ARRAY_A);
$title = $post_id['post_title'];
$content = $post_id['post_content'];
return $content;
}
echo get_my_content($page);
So long as you have your get_my_content()
function defined, you can use it anywhere you need to.