Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

what-is-diference-wp-get-attachment-url-wp-get-attachment-src-get-post-thumb

wp_get_attachment_url($id)

Returns a full URI for an attachment file or false on failure. Here id is attachment post id

Example

echo wp_get_attachment_url( $id ); 
echo wp_get_attachment_url( 12 );
$example_url = wp_get_attachment_url( get_post_thumbnail_id() );
echo '<div style="background-image:url('.$example_url.');"></div>';
wp_get_attachment_image_src()

return array value of image attribute

Example

wp_get_attachment_image_src( int $attachment_id, string|array $size = 'thumbnail', bool $icon = false )

$image_attributes = wp_get_attachment_image_src( $attachment_id = 8 );
if ( $image_attributes ) : ?>
    <img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>" />
<?php endif; ?>
get_post_thumbnail_id() return featured image id

Example:

get_post_thumbnail_id($post_id)
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
Source by wordpress.stackexchange.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
1+3 =