Skip to content

Instantly share code, notes, and snippets.

@rodica-andronache
Last active September 5, 2016 08:03
Show Gist options
  • Save rodica-andronache/d192e9bc7ee13a9926e5ce787800cb96 to your computer and use it in GitHub Desktop.
Save rodica-andronache/d192e9bc7ee13a9926e5ce787800cb96 to your computer and use it in GitHub Desktop.
Migrate old favicon to new favicon option from core
function bookrev_migrate_favicon(){
if ( function_exists( 'wp_site_icon' ) ) {
if ( get_theme_mod('old-favicon-image') ) {
$id = attachment_url_to_postid( get_theme_mod('old-favicon-image') );
if ( is_int( $id ) ) {
update_option( 'site_icon', $id );
}
remove_theme_mod( 'old-favicon-image' );
}
}
}
add_action( 'after_setup_theme', 'bookrev_migrate_favicon' );
It can also be applied to custom logo
function bookrev_migrate_logo(){
if ( get_theme_mod('old-header-logo') ) {
$logo = attachment_url_to_postid( get_theme_mod( 'old-header-logo' ) );
if ( is_int( $logo ) ) {
set_theme_mod( 'custom_logo', $logo );
}
remove_theme_mod( 'old-header-logo' );
}
}
add_action( 'after_setup_theme', 'bookrev_migrate_logo' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment