I've got a function inside a functions.php file that defines certain variables:

add_action( 'the_post', 'paginate_slide' );

function paginate_slide( $post ) {

    global $pages, $multipage, $numpages;

    if( is_single() && get_post_type() == 'post' ) {

    $multipage = 1;
    $id = get_the_ID();
    $custom = array();
    $pages = array();
    $i = 1;

    foreach( get_post_custom_keys() as $key )
        if ( false !== strpos( $key, 'slide' ) )
            $custom[$key] = get_post_meta( $id, $key, true);

    while( isset( $custom["slide{$i}-title"] ) ) {

        $page = '';
        $tzTitle = $custom["slide{$i}-title"];
        $tzImage = $custom["slide{$i}-image"];
        $tzDesc = $custom["slide{$i}-desc"];
        $tzEmbed = $custom["slide{$i}-embed"];

        $page = "<h2>{$tzTitle}</h2><img src='{$tzImage}' />";
        $pages[] = $page;
        $i++;
    }

    $numpages = count( $pages );
    }
}

Let me output a few of these variables inside a template.php file like so: <?php echo $tzDesc; ?> however i can't appear to have it to operate. From things i understand concerning the variables scope, to be able to call these variables in another place I have to define them inside the global scope and give them a call as global within this function like Used to do the $pages, $multipage, $numpages;. Which should let me plug individuals variables in where I want them. The issue is after i remove them from the function and define them above inside the global scope the whole fucntion reduces.

How should i structure this in order to call <?php echo $tzDesc; ?> any place in the website and also have it echo the defined info?

I'm not sure if the matters but this really is on the wordpress site.

If you wish to use <?php echo $tzDesc; ?> anyway, you should define $tzDesc like a global variable. However, I do not recommend doing this as global variables are thought poor programming practice.

A much better solution is always to possess the paginate_slide() add $tzDesc (along with other values) towards the $post object. This way you can get these variables when you call the_post(). Should you follow this path, make sure to namespace you variables:

$post->ns_tzDesc = $tzDesc;