Unlock your potential with a Pro Membership
Here is where you propel your career forward. Come join us today. Learn more.
Convert into Utility File – for Reuse
Lab: Automate Asset Versioning – Better Asset Versioning
Video Runtime: 14:30
The code that we’ve built is a utility file. But for it to be reusable, we need to do the following:
- Remove the enqueueing callback and put that into a separate file.
- Protect the utility functions from loading into memory if they’ve already been loaded by another plugin/theme.
In this episode, we’ll do some refactoring and housekeeping. But you also get to learn about this design pattern and why it is so critical in our strategy:
if ( ! function_exists( 'get_theme_version' ) ) : /** * Get the theme's version. * * When in development/mode mode, it uses the style.css modification time. * Else, it grabs the version number from the stylesheet. * * @since 1.0.0 * * @return string|int */ function get_theme_version() { // code deleted for brevity } endif;
In this episode, you’ll refactored in the Twenty Seventeen and Genesis Sample themes. Plus, we’ll demonstrate including our new utility file into a plugin and theme at the same time.
Your best friend is code, Tonya is making the introductions.
Episodes
Total Lab Runtime: 02:27:07
- 1 Lab Introductionfree 11:19
- 2 Why is Version Number Necessary?free 16:30
- 3 Version Numbering Schemepro 06:47
- 4 Forget Hard Coding Version Numberpro 15:02
- 5 Forget Hard Coding - Grab Stylesheet's Versionpro 05:19
- 6 Forget Hard Coding - Genesispro 05:17
- 7 Load the Theme's Minified Stylesheetpro 10:23
- 8 Strategy Session: Minified or Full for Theme Versionpro 12:25
- 9 Load the Minified Stylesheet in Genesispro 05:04
- 10 Refactor to Improve Our Codepro 11:20
- 11 Applying It to Scriptspro 18:14
- 12 Apply it to Scripts - Genesispro 09:13
- 13 Convert into Utility File - for Reusepro 14:30
- 14 Wrap it Upfree 05:44