Skip to content

Instantly share code, notes, and snippets.

@kraftbj
kraftbj / functions.php
Created January 31, 2014 18:49
Use image from the latest post for the og:image tag on the home page
<?php
function fb_home_image( $tags ) {
if ( is_home() ) {
$latest_post = get_posts("post_type=post&numberposts=1");
$latest_post = $latest_cpt[0]->ID;
if ( class_exists( 'Jetpack_PostImages' ) ) {
$post_images = Jetpack_PostImages::get_images( $latest_post, array( 'width' => 200, 'height' => 200 ) );
if ( $post_images && !is_wp_error( $post_images ) ) {
$image = array();