How to set global variable in functions.php

You can turn your snippet into a function that returns the post thumbnail URL of a post:

function wpse81577_get_small_thumb_url( $post_id ) {
    $thumbSmall = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'small' );
    return $thumbSmall['0'];
}

Usage, supplying the ID of a post:

<?php echo wpse81577_get_small_thumb_url( 59 ); ?>

Leave a Comment