How to get the URL ONLY from the displayed image in wordpress

I am using timthumb.php and should be able to get the URL of the displayed image of the message, when I use functions like the_post_thumbnail , it does more than just a URL.

Here is the code, so capital letters are where I need to insert the exact url, any help would be great, thanks.

 <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> <img src="<?php bloginfo('template_url'); ?>/wp-content/themes/limerickfc/timthumb.php?src=<?php URL OF FEATURED IMAGE ?>&h=760&width=474" alt="" title="<?php the_title(); ?>" /> </a> 
+4
source share
2 answers

If your thumbnail images are large enough to do what you need:

 <?php wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?> 

Otherwise, you will need something like:

 <?php $src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(300, 300), false, ''); echo $src[0]; ?> 

EDIT: The array(300, 300) bit is the size of the image you want to get. WP will replace any image that has at least the same image as you. You can also use 'thumbnail' , 'medium' , 'large' or 'full' to select one of the pre-configured sizes, as well as any name defined by add_image_size() in your template or plugins.

+19
source

First enter the identifier of the thumbnail shown:

 $thumb_id = get_post_meta( $post_id, '_thumbnail_id', true ); 

One way to do this:

 $thumb = get_post($thumb_id); $thumb_url = $thumb->guid; 

Another way:

 $thumb_url = wp_get_attachment_url( $thumb_id ); 

Be careful what is stored in the GUID and what get_attachment_url returned. The application URL (depending on the configuration) may be the page on which the attachment is available (not the URL of the raw file, but the page that uses attachment.php ).

+2
source

Source: https://habr.com/ru/post/1438255/


All Articles