Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created April 18, 2019 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/5e6e860d191ae20c00107983f4db2830 to your computer and use it in GitHub Desktop.
Save billerickson/5e6e860d191ae20c00107983f4db2830 to your computer and use it in GitHub Desktop.
<?php
/**
* Use Genesis Image in Yoast Schema
* If no featured image is specified, genesis_get_image() uses first uploaded to post
*
* @see https://www.billerickson.net/code/yoast-schema-use-genesis-image/
*/
function be_yoast_schema_use_genesis_image( $graph_piece ) {
if( ! is_singular() )
return $graph_piece;
if( empty( $graph_piece['image'] ) && function_exists( 'genesis_get_image' ) ) {
$image = genesis_get_image( array( 'format' => 'url' ) );
if( !empty( $image ) )
$graph_piece['image'] = array(
'@id' => $image . '#primaryimage',
'@type' => 'ImageObject',
'url' => $image,
);
}
return $graph_piece;
};
add_filter( 'wpseo_schema_article', 'be_yoast_schema_use_genesis_image' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment