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
- How to get URL of current page displayed?
- How to add a class to the attachment images
- Change the filename format of saved featured images
- How to register images uploaded via FTP in media library?
- What is the best practice for escaping data URIs?
- Rename image uploads replacing “width” and “height” in filename with “medium”, “large”, “small”
- How do I get the author’s page url from their ID?
- Dynamic URL to reference custom PHP files
- Debugging upload problem: What part of WP does actual image-resizing?
- Conditional Statement – check if post has an attachment image
- How to upload imagick resource to media in wordpress
- Use Filename for Alt and Title Tags
- How do I get images (with a thumbnail preview) to show in search results?
- Add custom HTML to posts page
- Add filename to attachment page url
- Newbie question: no index.php? in my plain wordpress permalink
- Assign a picture URL to a page via PHP
- Change logo based on incoming domain
- How to scale image with equal width and height without distortion?
- Get most recent media upload
- Convert all images to PNG on file upload
- Escape post image attachments added to template
- Auto crop images in WordPress
- Display post image with fancybox
- Get different images for mobile and desktop with php, advanced custom fields without using js and ajax
- Cannot display or echo alt text on featured image
- 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?
- Extend PHP regex to cover “srcset” and “style” attributes
- get_children displaying images removed from the page
- Why my image upload button is not working in wordpress widget area?
- “imagejpeg” function is not working in wordpress
- Display image from an external rss feed on wordpress without plugins
- Get URL Parameters from referer
- WordPress function when file is uploaded, deleted or edited
- Download images from media library to computer in BULK?
- Three Questions with Twenty Eleven theme
- Get the URL of the page from which an ajax request has been launched within ajax callback
- How to loop through all the attached images in a post, and get their url one by one
- Division by zero error in image.php
- Clickable image link sends people to wrong URL
- Post’s ID pattern?
- Only show image from custom field when present
- Upload non-featured image to image field
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- change default RSS feed URL
- Display an image based on field value
- Nginx WordPress and another Web app URL structure
- Image rotation issue (horizontal picture uploading as vertical) — Exif issue?
- WordPress İmages Upload & Delete Error
- Call featured image url
- Creating customized php files in theme folder
- Use an anchor link to open an iframe inside a WordPress page
- Adding custom url to readmore link using get_permalink()
- Comment_author_url doing nothing
- Adding a ‘style=’ bit to image_send_to_editor output
- Modifying WP URL handing code?
- How to deal with a GET variable of ‘name’?
- Workaround for og:image unsupported webp image type, Yoast SEO?
- Generate images with html2canvas and the woocommerce api
- WordPress api post image raw data without being blank in media library
- Unable to display multiple parameters from url by javascript through shortcodes
- Retrieve alt text by referencing the img src
- Show next image in array if page is revisited by same logged user
- WordPress loading all local images from specific directory?
- Add Link to PHP message
- I have a background-image in css file but don’t show in site.how to fix this prblm. i sent screenshot. thx
- How do I stop an Image Address from loading in the Browser?
- Current WordPress Page Title as Search Parameter into A Tag
- How to add a PHP scripts into WordPress
- How does one make a URL return dynamic JSON with custom Content Type?
- Require advice handling a URL redirect from a Third Party. URL Params need to populate and then forward to payment
- How to include different html tags in the header for different pages?
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- changing static link to relative link
- Create a dynamic buddupress tab
- add class to background image
- Save the outputted image into the Media Library, with a different filename and extension
- How to resize an image server-side before upload?
- Creating image gallery in wordpress
- Magento and WordPress URL integration [closed]
- Snapshot Theme from WooThemes — empty ‘alt’ attribute
- Setting post thumbnail sizes in template file and functions.php
- How to remove parent section in an attachment URL in wordpress?
- upload images on front by user using form
- HTML in PHP problem [closed]
- Adding slides to an existing carousel manually
- An automatic way to crop images of different sizes
- Remove default Image Sizes
- How to create a WordPress PAGE in another folder?
- Add/alter image attribute before render
- How Create Automatically Image jpg.webp from image .jpg without delete or change original images upload
- How can add alt tag in following code. Image are showing dynamic in wordpress