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
- and
- How to add code to Header.php in a child theme?
- How to Link External jQuery/Javascript files with WordPress
- Add tags to the section via functions.php
- Why is wp_head() creating a top margin at the top of my theme header?
- How can I remove the site URL from enqueued scripts and styles?
- How to add stylesheets only to pages with specific shortcode?
- force enqueue script to be first in order of prominence
- What does l10n.js do in WordPress 3.1? And how do I remove it?
- Any advantage of using wp_scripts and is_IE when enqueuing scripts
- Remove meta robots tag from wp_head
- 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
- wp_head() gives me some weird CSS
- How can I modify what is being output in wp_head, whether by a theme or WordPress in general?
- Removing specific style from wp_head
- Change Page’s Tag Using functions.php File
- Is there a filter to define the OG image on a given post?
- How to control initial wp_head() output?
- Hook into wp_head(); in a plugin
- How can I reduce the amount of files loaded/included per plugin?
- when should an action be added to init and when should it be added to wp_head
- Change title in head on Archive page
- How can I get wp_head() as a string instead of echoing it?
- Add code into on a per page/post basis
- Set Custom Post feature image as og:image
- Modify page title format (when using title-tag)
- Display custom_background outside wp_head()
- How to load different css file for different pages
- Putting content into header.php without using wp_head
- Track down where script is being enqueued from
- Wp_head and wp_footer vs wp_enqueue_script javascript files?
- use add_action(‘wp_head’) in a widget for generating dynamic CSS styles
- How can you upload an image from within a settings page?
- Change meta tags programatically
- How to use wp_enqueue_style() and wp_enqueue_script() only when needed?
- How to properly insert a stylesheet in wp_head
- append stylesheet via shortcode
- Change dns-prefetch to preconnect with correct protocol
- Remove specific CSS and JS from the head
- Using auth_redirect returns cannot modify header information
- Searching hook to set cookies before and avoid “headers already sent”
- Sharing post in Facebook shows UTF8 invalid character �
- How to load plugin before the wordpress jquery?
- Why does wp_enqueue_script ignore my ‘wp_head’ hook?
- wp_head() remove redundant scripts?
- How can I make new .css file in child theme override styles in child theme’s style.css
- Manipulating wp_head content
- Generating the ogp tags in theme
- FB – Comment Moderation Tool bug or error in the code?
- Manually add admin bar
- How can i remove JUST the title tag from wp_head() function?
- sharing video on facebook from wordpress
- Indenting (tabbing) WP_head
- Disable wordpress from including jQuery in the head section
- wp_head() not inserting the default stylesheet style.css
- Deregister CSS style link ‘open-sans-css’
- How to add iOS & fav icons to the theme?
- Filter out some plugin action in wp head / wp_footer
- Open graph metadata isn’t pulled on Facebook until after I run that specific link through the debugger