get_post_thumbnail_id()
is going to default to using the $post
global. That global is set to each post in turn as the Loop runs, so at the end of the Loop it will be set to the last post.
The easiest thing to do would be to set $image
before the Loop runs, but wp_reset_query
would do it too, if resetting the Loop does not through off other code on your page.
Also, you mention that you need this for Javascript. Javascript alone should be able to pick out the first URL in the markup that is already being printed by the Loop.
Related Posts:
- Echo URL of large version of Featured Image
- Scrape external webpage for first image and add it to new post
- I’m unable to call img path using single quotes in an array?
- Prepend to all image URLs with PHP, only for mobile devices
- bloginfo url in javascript
- Colon is Missing In My Website Url in WordPress
- How to change redirection route to a php page for making it only accessible by logged-in members?
- How to use $_GET function WordPress backend
- How to get next image with this code from same post?
- Unread Repeater field IMG alt not working
- Can’t upload image using media_sideload_image
- Upload multiple images to a Woocomerce product
- How to use thumbnail size of image if I’m only using src to get image
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- Extend PHP regex to cover “srcset” and “style” attributes
- Accessing an image folder inside public web directory
- get_children displaying images removed from the page
- Why is image hard cropping for one image using add_image_size not working?
- Enable custom logo upload if logo is not in header
- Why my image upload button is not working in wordpress widget area?
- My php header() function is not working [closed]
- How to make own crop image function for WordPress plugin
- “imagejpeg” function is not working in wordpress
- Display image from an external rss feed on wordpress without plugins
- Create custom permalinks to show Custom Post Type’s relationship?
- Search Query: how to construct a search string from two select elements?
- Get URL Parameters from referer
- Need help enqueueing webfonts
- Redirect to another page using contact form 7? [closed]
- WordPress automatically adds links to uploaded images
- WordPress function when file is uploaded, deleted or edited
- Download images from media library to computer in BULK?
- Three Questions with Twenty Eleven theme
- Why is $wp->request empty in WordPress 6.0?
- Get the URL of the page from which an ajax request has been launched within ajax callback
- How to check if the current page is at a specified path in the URL?
- How to loop through all the attached images in a post, and get their url one by one
- Which function crops images in wordpress?
- Division by zero error in image.php
- Resize image to specific dimension (X to Y ratio)
- How to pass a PHP $_GET variable and fetch/output it?
- How can I automatically resize up images to fit into all of my registered image sizes
- Clickable image link sends people to wrong URL
- Post’s ID pattern?
- Only show image from custom field when present
- Timthumb.php image gallery not working on Multisite WordPress
- Upload non-featured image to image field
- Where are the src and srcset sizes coming from?
- HTML showing after PHP code in tag
- Only show first image in foreach loop
- trying to get wp_get_attachment_url to output clickable link
- Change default gallery images – Currently they are displaying full size imagese
- Creating black and white copy of an image [closed]
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- change default RSS feed URL
- Get the id of all images in a post
- Shortcode function doesnt work without caption
- How do i add slugs to a URL, but still redirecting to the same page
- Get featured image with custom size outside WordPress
- Can’t change website Title on wordpress
- Images Uploaded saving onto older/previous year folders
- Display an image based on field value
- Else/If Statement to Display Photo Descriptions
- Add valid XHTML closing img tags to WordPress galleries
- How to set a featured image (thumbnail) with PHP?
- Convert canvas to image and upload image to server
- Nginx WordPress and another Web app URL structure
- Controlling image output size ACF repeater [closed]
- Image rotation issue (horizontal picture uploading as vertical) — Exif issue?
- WordPress İmages Upload & Delete Error
- How to use title attributes in sidebar widget?
- how to get attached file url for current post?
- Call featured image url
- Creating customized php files in theme folder
- Generate responsive post thumbnails of same size
- How to Make Thumbnail of Post Stay Animated
- How do I include an external PHP file in a subdir WordPress install?
- How to add PHP pagination to wordpress
- Use an anchor link to open an iframe inside a WordPress page
- Adding custom url to readmore link using get_permalink()
- How to set base url for php widget
- Comment_author_url doing nothing
- Attaching images to posts manually (i.e. with custom code, without the use of an API)
- Adding a ‘style=’ bit to image_send_to_editor output
- Convert all uploaded PNG files to PNG-8 format
- foreach repeat html structure after every nth for attachment [closed]
- CSS images don’t show up with bloginfo
- Modifying WP URL handing code?
- How to deal with a GET variable of ‘name’?
- how to show images without passing it to timthumb.php file for resizing
- WordPress permalink issue
- How to internationalize header image?
- WordPress is removing query variables like page, p from the URL of a custom static page
- Some problems in custom widget
- Displaying images outside the content
- Offer Download Links for Product Images
- Checking page before applying image restrictions while uploading
- Workaround for og:image unsupported webp image type, Yoast SEO?
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- Generate images with html2canvas and the woocommerce api