Last active
February 15, 2019 11:07
-
-
Save christophherr/c4cc901342cdce2302d2aad846ec4715 to your computer and use it in GitHub Desktop.
Change custom_logo Schema markup
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
/** | |
* Use one of the filters. Not multiple... | |
* I'd use the third. | |
*/ | |
add_filter( 'wp_get_attachment_image_attributes', function ( $attr ) { | |
if ( isset( $attr['class'] ) && 'custom-logo' === $attr['class'] ) { | |
$attr['itemprop'] = 'image'; | |
} | |
return $attr; | |
} ); | |
add_filter( 'get_custom_logo', function() { | |
$custom_logo_id = get_theme_mod( 'custom_logo' ); | |
$html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>', | |
esc_url( home_url( '/' ) ), | |
wp_get_attachment_image( $custom_logo_id, 'full', false, array( | |
'class' => 'custom-logo', | |
'itemprop' => 'image', | |
'alt' => '', | |
) ) | |
); | |
return $html; | |
}); | |
/** | |
* Fix Google Schema error, "The property logo is not recognised by Google for an object of type WPHeader". | |
* | |
* @author Mike Hemberger, Gary Jones | |
* @param string $html The logo HTML. | |
* @return string The modified HTML. | |
*/ | |
add_filter( 'get_custom_logo', function( $html ) { | |
return str_replace( 'itemprop="logo"', 'itemprop="image"', $html ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or this: