Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ericnicolaas/fa64a99ef02f9efbcdf89345c74d6aff to your computer and use it in GitHub Desktop.
Save ericnicolaas/fa64a99ef02f9efbcdf89345c74d6aff to your computer and use it in GitHub Desktop.
Code snippet for update script to use new theme logo
<?php
/**
* Theme Update Script
*
* Runs if the logo has not been set yet.
*/
function prefix_update_check() {
// Return if update has already been run
if ( -1 == get_theme_mod( 'custom_logo', -1 ) ) {
return;
}
// If we're not on 3.5 yet, exit now
if ( ! function_exists( 'the_custom_logo' ) ) {
return;
}
// Set a default value of false for the custom logo
$custom_logo = false;
// If a logo has been set previously, update to use logo feature introduced in WordPress 4.5
if ( get_theme_mod( 'logo', false ) ) {
// Since previous logo was stored a URL, convert it to an attachment ID
$logo = attachment_url_to_postid( get_theme_mod( 'logo' ) );
if ( is_int( $logo ) ) {
$custom_logo = $logo;
}
remove_theme_mod( 'logo' );
}
set_theme_mod( 'custom_logo', $custom_logo );
}
add_action( 'after_setup_theme', 'prefix_update_check' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment