-
-
Save billerickson/5e6e860d191ae20c00107983f4db2830 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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