Skip to content

Instantly share code, notes, and snippets.

@BinaryMoon
Created May 20, 2017 10:36
Show Gist options
  • Save BinaryMoon/0ae3a64e7e194c5d950507885be83b8d to your computer and use it in GitHub Desktop.
Save BinaryMoon/0ae3a64e7e194c5d950507885be83b8d to your computer and use it in GitHub Desktop.
Replace jetpack logo with custom logo
<?php
/**
* Check for Jetpack logo and replace with core logo functionality.
*
* @package granule
*/
/**
* Remove Jetpack site-logo functionality and replace with support for custom logo.
*
* @return boolean
*/
function granule_remove_site_logo() {
// Current theme does not support Jetpack logos so exit.
if ( ! current_theme_supports( 'site-logo' ) ) {
return false;
}
// Current theme supports custom logo already so exit.
if ( current_theme_supports( 'custom-logo' ) ) {
return false;
}
// Get the site logo properties.
$properties = get_theme_support( 'site-logo' );
// Get image sizes.
global $_wp_additional_image_sizes;
// Make sure the specified size exists.
if ( ! isset( $_wp_additional_image_sizes[ $properties[0]['size'] ] ) ) {
return false;
}
// Set image properties.
$image_properties = $_wp_additional_image_sizes[ $properties[0]['size'] ];
// Remove the site logo support.
remove_theme_support( 'site-logo' );
// Add support for the custom logo.
add_theme_support(
'custom-logo',
array(
'height' => $image_properties['width'],
'width' => $image_properties['height'],
'flex-height' => false,
'flex-width' => false,
)
);
/**
* Create a new function that outputs the custom logo (in case the jetpack
* logo functions are being used).
*/
function jetpack_the_site_logo() {
the_custom_logo();
}
}
/**
* Set priority as later than the default priority so that it can remove any
* options that might have been set.
*/
add_action( 'after_setup_theme', 'granule_remove_site_logo', 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment