I’ve been updating several of my themes to support the new custom logo feature that is being introduced in WordPress 4.5 (read about it here).
Most of my themes already had a logo option, so part of adding support for this new feature has been to build an update script to migrate the previously saved value (generally saved to the theme mod “logo”), to the new theme mod “custom_logo”.
I assume a lot of other theme authors will also be doing this, so I’m sharing my update code in case it can save someone a few minutes.
A few things to note:
- You’ll likely need to tweak it to match your current theme_mod/setting for the logo.
- I saved my logo value as a URL, so this script converts it to an attachment ID before saving it into the new theme_mod
[gist id=”7af792846055f8130f3b”]
If you see any improvements that can be made, feel free to edit the Gist!
Great information Devin. Thanks for helping so many people keep up with WordPress implementations.
This piece of code is OK for Custom Logo feature for the existing theme. But if someone is an using option panel like Redux, they can’t use this code so how they can manage it easily?
Same basic process. Redux saves the logo image to the database (either the path of the attachment id), you just need to fetch that instead where get_theme_mod( ‘logo’ ) is used.