On a single post page the $post
variable should work for you. It is set well before the page header prints. You will need get_post_thumbnail_id
and wp_get_attachment_image_src
if (is_single()) {
$thumbid = get_post_thumbnail_id($post->ID);
$imgsrc = wp_get_attachment_image_src($thumbid);
$src = $imgsrc[0];
// wp_die(var_dump($src)); // debugging/confirmation
}
I don’t know how your theme is written or how that meta tag is inserted so I can’t say exactly how to insert the image source into that tag, but the above will get you the URL.
$src
will be NULL
if there is no featured image so use isset
or empty
to check the variable before using it.
Related Posts:
- Including post thumbnail url in loop’s post object to reduce number of queries
- WP Loop. If featured image is a panorama (3:1 ratio) execute some code
- Pulling in featured image into default recent posts widget
- Closing the loop…featured image variable based on post id
- WordPress get post thumbnail url
- How to output thumbnail twice in a loop
- Default featured image set as background image [closed]
- How to check all items in a loop have post thumbnail?
- Thumbnail Image Rounded Corners w CSS (or any other good method)
- wp_get_attachment_url not fetching URL?
- Thumbnail of the latest posts page
- Pages with a loop (index, archive) are loading the first image as post_thumbnail
- Display Featured Image
- Place the Featured image on a post, before the first via code
- Get excerpt using get_the_excerpt outside a loop
- Retrieve each widget separately from a sidebar
- how to upload image using wp_handle_upload
- Avoiding using a loop to access a single post
- Adding ‘current_post_item’ class to current post in the loop
- WordPress Alphabetical Glossary close div in loop
- Where should I use post_class()?
- Landing Page – Redirect Loop?
- How to make multiple Column in archive Page?
- Sort Popular Posts by Views for the Last Week
- Filtering posts by multiple taxonomies
- Is it possible to display previous post revision?
- Query sticky posts with thumbnails
- Fix inefficient loop breaks post.php on form submit
- Help with Changing loop.php?
- Adding shortcode closing tag after a loop
- Get Pagination (WP-PageNavi) not to work
- Filtering The Loop For Single Page and Blog Page
- the_content() seems to block my ACF-code
- Pulling current post/page data into header.php
- Removing the_content() from the page
- Change front-page layout after x amount of posts ( while in the same loop)
- How can i use the same template file with a widget and category loop?
- Filter the loop by categories using checkbox form
- Duplicated posts on category page
- WordPress loop: exclude if it is the latest post
- Apply an Incremental Counter in an Array Function
- angularjs not displaying all posts
- query_posts() vs get_posts() multiple loops [duplicate]
- Page-loop is looping content from custom loops on the same site. How to avoid that?
- How do I make a variable available inside partials?
- WordPress: Loop Help
- is_active-sidebar loop
- Unable to change the “Read more” text inside the_excerpt
- Display Post Author Link above the loop
- Enabling users to control custom loop’s query
- Conditional: IF current user has NOT commented on current post (not including post author)
- Loop counter style
- Can I add generic numbering HTML classes to items as a loop runs?
- Change post order by meta key, per post basis
- Loop Problem: Displays same set of post for all categories
- 3 random images from custom post type, each in a div with a diffrent class
- Custom Post Type on Homepage – Studiopress Genesis Framework
- New loop vs widget
- display post format text in loop
- Yoast taking over my WordPress title tag [closed]
- Pagination broken after using 2 loops to show content
- How do i find and restore a sidebar that i accidentally deleted? [closed]
- Posts not showing
- Use BuddyPress data in loop (mkdir)
- Wrap every four posts within a div [duplicate]
- Get most recent post for every term in a given taxonomy type
- using update_user_meta to rank users
- Can’t grab author info outside of the loop
- Custom Blog Loop on Home Page
- How do i create a list-posts-page?
- Ascending order has strange effects on wordpress loop
- Is file_exists() compatible with timthumb.php? [closed]
- get post images to link to external sources
- Set depth of pages to fetch
- Trying to get all links in my posts
- Creating a User-Adjustable chart in WordPress
- Archive: Lists itself
- Thumbnail wouldn’t scale to size properly
- Reorder posts in a loop: have the posts by one particular author below the others
- How to execute a user loop with shortcode
- how to get author comment inside the loop?
- How to create loop in custom page, and get id from url into this loop?
- How to fix pagination for custom loops?
- Check to see if a field is within an array in twig
- Loop Posts Outside of WordPress Installation
- How To Loop Through list with Custom Post Types
- Display single post inside accordion based on form submission results
- One page loop issue with posts
- Humanmade | Custom meta box class: How to display a repeatable meta box group?
- Building theme so user can change header image [closed]
- display only parent replies count in index.php
- using the loop on a page
- While loop inside another while loop
- get_page() unlike Loop returns the post content without html tags. How can I fix this?
- Problem with ms-thumb-frame-selected class in Master Slider
- Fix html inside a for loop [closed]
- Display all posts in a page code for template
- Insert multiple custom components after x-number of posts
- Hook in the loop after the first post
- How home my code doesn’t display any feature image? Looping through post from a taxonomy and not getting feature images back