Skip to content

Instantly share code, notes, and snippets.

@christophherr
Last active February 15, 2019 11:07
Show Gist options
  • Save christophherr/c4cc901342cdce2302d2aad846ec4715 to your computer and use it in GitHub Desktop.
Save christophherr/c4cc901342cdce2302d2aad846ec4715 to your computer and use it in GitHub Desktop.
Change custom_logo Schema markup
/**
* 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 );
});
@JiveDig
Copy link

JiveDig commented Jul 27, 2018

Or this:

/**
 * Fix Google Schema error, "The property logo is not recognised by Google for an object of type WPHeader".
 *
 * @param   string  $html  The logo HTML.
 *
 * @return  string  The modified HTML.
 */
add_filter( 'get_custom_logo', function( $html ) {
	$html = str_replace( 'itemprop="logo"', 'itemprop="image"', $html );
	return $html;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment