When your website means business.

PHP, WP/CP | Type: PHPWordPress Template Tags

Sometimes you need to turn a WP template tag into a PHP variable, so you can construct a proper bit of code.

$url = get_template_directory_uri();
$link = get_the_permalink();
$title = get_the_title ();
if ( has_post_thumbnail() ) {
    echo '<a href="'.$link.'">';
    echo get_the_post_thumbnail( $post->ID, 'thumbnail' );
    echo '</a>';
    } else {
    echo '<a href="'.$link.'"><img src="'.$url.'/images/blank.jpg" alt="no image" /></a>';

NOTE: Thumbnail tag above creates the entire img HTML. Attributes can be specified as so (array would be added to above query):

$thumbnail_attr = array(
    'src'   => $src,
    'class' => "attachment-$size",
    'alt'   => 'alt here',
    'title' => 'title here',
the_post_thumbnail($image_size , $thumbnail_attr);

Reference Links

We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.