WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/22/2015 04:14:15 AM (5 years ago)
Author:
wonderboymusic
Message:

Media: Add new functions, get_the_post_thumbnail_url() and the_post_thumbnail_url().

Adds unit tests.

Props dipesh.kakadiya, swissspidy, atomicjack.
Fixes #33070.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-thumbnail-template.php

    r34167 r34373  
    171171    return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr );
    172172}
     173
     174/**
     175 * Return the post thumbnail URL.
     176 *
     177 * @since 4.4.0
     178 *
     179 * @param int|WP_Post  $post Optional. Post ID or WP_Post object.  Default is global `$post`.
     180 * @param string|array $size Optional. Registered image size to retrieve the source for or a flat
     181 *                           array of height and width dimensions. Default 'post-thumbnail'.
     182 * @return string Post thumbnail URL or empty string.
     183 */
     184function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) {
     185    $image = wp_get_attachment_image_url( get_post_thumbnail_id( $post ), $size );
     186    return isset( $image ) ? $image : '';
     187}
     188
     189/**
     190 * Display the post thumbnail URL.
     191 *
     192 * @since 4.4.0
     193 *
     194 * @param string|array $size Optional. Registered image size to retrieve the source for or a flat
     195 *                           array of height and width dimensions. Default 'post-thumbnail'.
     196 */
     197function the_post_thumbnail_url( $size = 'post-thumbnail' ) {
     198    echo get_the_post_thumbnail_url( null, $size );
     199}
Note: See TracChangeset for help on using the changeset viewer.