Site icon Hip-Hop Website Design and Development

Add a variable in functions.php and call it in single.php

I am new to PHP and am building a WordPress theme. I would like to add a variable in the functions.php and use it in single.php as an if statement. At present, my single.php has the following code –

<?php 
  $prevPost = get_previous_post();
  $prevthumbnail = get_the_post_thumbnail($prevPost->ID, 'keepreading-thumb');

  if ( $prevPost ) : ?>
    <?php previous_post_link('%link',"$prevthumbnail"); ?>
    <h3><?php previous_post_link('%link'); ?></h3>
    <p><?php echo excerpt(25); ?></p>
  <?php endif; 
?>

I would like to have the $prevPost and $prevthumbnail variables to be defined in functions.php and would like to use them in an “if statement” in single.php.

P.S – I am a newbie in coding and would appreciate it if you can give me an answer in detail. Thank you…