Yes, the global post object is already set when wp_head
is called. An example for a function body from this post:
// restricted to singular pages only
if ( ! is_singular() )
return;
// there has to be a featured image set
$thumb_id = get_post_thumbnail_id();
if ( empty ( $thumb_id ) )
return;
// FALSE or array
$image = wp_get_attachment_image_src( $thumb_id );
// nothing found for unknown reasons
if ( empty ( $image ) )
return;
// make sure it is a real url
$src = esc_url( $image[ 0 ] );
// esc_url() returns an empty string for some invalid URLs
if ( '' !== $src )
print "<meta property='http://ogp.me/ns#image' content="$src" />";
Related Posts:
- How to find which plugin is outputting Open Graph tags to
- WordPress Code Flow
- How can i get the name parameter defined in get_header?
- Is there a way to read or list wp_head() contents?
- Multi-page posts do not get indexed by Google due to canonical URLs
- Remove rel=’dns-prefetch’ href=’//maps.google.com’ from wp-head
- How to remove pingback from head?
- wp_head() outputs in body
- Change dns-prefetch to preconnect for external enqueued resources
- How to remove unnecessary elements in the HTML document head
- wp_head() not including styles and javascripts after a template redirect
- Removing Visual Composer head meta (works alone but not with IF)
- removing wordpress generated code from the head section?
- Change default s.w.org dns-prefetch resource hint value
- using wp_head in body tag for css style
- Use wp-load() and wp_head() to render a page’s header outside of WordPress
- Set title of page using custom page template
- How do I add a logo to my website?
- Set up description meta automatically
- Why would wp_head() cause the menus to break?
- wp_head function outputs after
- Remove_action inside a function
- Does adding a callback like this to wp_head allows you to add additional content?
- How can i remove JUST Description tag from wp_head() function?
- Custom page with WP Header showing Page not found title
- Getting the contents of wp_head while in admin?
- Wp_head () affecting my images layout
- How to add meta tags inside single image page?
- How to store wordpress functions (wp_head(),wp_footer()) in a javascript variable?
- “Warning: count()” printing in Page templates
- How can I edit a meta description
- How do I add Facebook OpenGraph meta tags for attachments in the header for a custom theme?
- Hide page name in wordpress page title
- Unable to apply selective loading
- why php tag is not working if i store and show it in wp_head?
- output specific location in the header
- Data validation for inline javascript
- Add OG meta tags to wp head
- How to Link External jQuery/Javascript files with WordPress
- Add tags to the section via functions.php
- Caching and Versioning for rtl.css
- How do I force wp_enqueue_scripts to load at the END of ?
- Two title tags in my header
- Removing specific style from wp_head
- when should an action be added to init and when should it be added to wp_head
- Change title in head on Archive page
- Add code into on a per page/post basis
- Display custom_background outside wp_head()
- Putting content into header.php without using wp_head
- use add_action(‘wp_head’) in a widget for generating dynamic CSS styles
- Change meta tags programatically
- Why does wp_enqueue_script ignore my ‘wp_head’ hook?
- wp_head() remove redundant scripts?
- Manually add admin bar
- Open graph metadata isn’t pulled on Facebook until after I run that specific link through the debugger
- Move all the JS files to the bottom|footer, the right way
- Add HTML to single post tag
- How to get full absolute url for post attachment?
- wp_head() – list hooked actions with priorities?
- Why wp_head() function not loading style.css?
- Modifying meta tags after doing ajax call in plugin
- Why I can’t modified jetpack default blank.jpg on og:image?
- How do I test my localhost WordPress project with VirtualBoxVM?
- How can I add Javascript in the header of all post pages and only post pages
- Open Graph in posts loop page
- Facebook social publisher and custom post type fields [closed]
- Custom script file enqueue has “?ver=4.5.1” when loading and doesn’t update
- How to get a single hook from wp_head()?
- How to hook into container
- Correctly implementing the Facebook Like button
- Remove swfobject.js in wp_head()
- Why does WP load so many files in the head of source code? How do I optimize it?
- How to load a stylesheet into wp_head from a custom widget?
- Adding Plugin Assets to Header
- Prefix the title tag, if IP address is the dev server
- How to manipulate the content within wp_head
- How can I pass a shortcode value to the head in wordpress functions.php
- Wrong image path within inline styles in the head
- Facebook Does Not Grab Correct og:Image
- How to style injected code in header section?
- Where are the contents of WP_Head
- OG:Audio facebook meta tags
- How to replace the existing metatag using the backend to insure a thumbnail image gets fetched when we share on social media?
- How Discord picks the author name and the url from a WordPress post?
- Wrong Open Graph image is shown (og:image) using yoast
- i create functions.php in plugin files but add_action (‘wp_head’, ‘function_name’) don’t work
- Remove style tags from head
- Adding Facebook Open Graph Code does not work for Media Library Attachment Pages
- how to edit open graph meta description programmatically and in which file
- custom COOKIE on custom page
- How can I remove the site URL from enqueued scripts and styles?
- Best use adding user generated JS/CSS to a theme with a plugin
- wp_head hook content showing up at top of RSS feed
- I add some js files from a plugin to a specific location
- How to output wp_enqueue_style() in HTML head instead of footer
- How can a ‘scripts’ directory be hooked into wp_head();?
- Particular meta tag – viewport – insertion when dealing with plugin
- Use WordPress Built In Jquery
- WordPress og:image not working in whatsapp?
- Why callback function is not working in wp_head hook?