• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Draft / Genesis Child Theme Load style.css with Version Number

Genesis Child Theme Load style.css with Version Number

Last updated on January 31, 2019 by Sal Ferrarello

By default Genesis uses the parent theme for the version number for style.css.

URL Parameter

This version number is used in the ver URL parameter, e.g.

https://example.com/wp-content/themes/bootstrap4-genesis/style.css?ver=2.8.1

where 2.8.1 is the version of Genesis running. This ver parameter is particularly helpful for cache busting (i.e. forcing the browser to load the latest version when when the file changes).

Setting URL Parameter in Genesis

We can replace this number by defining CHILD_THEME_VERSION in our PHP code (e.g. in functions.php).

define( 'CHILD_THEME_VERSION', '7.8.9' );

Now, the value of ver will be 7.8.9.

https://example.com/wp-content/themes/bootstrap4-genesis/style.css?ver=7.8.9

Use the Version in style.css

Since we are already defining the theme version number in the header of style.css

/**
 * Theme Name: Bootstrap4 Genesis
 * Theme URI: https://github.com/salcode/bootstrap4-genesis
 * Author: Sal Ferrarello
 * Author URI: https://salferrarello.com
 * Description: WordPress Genesis Child Theme using Bootstrap 4
 * Version: 1.0.0

We can read this value with wp_get_theme()->get( 'Version' ) and set CHILD_THEME_VERSION to this value.

if ( ! defined( 'CHILD_THEME_VERSION' ) ) {
    define( 'CHILD_THEME_VERSION', wp_get_theme()->get( 'Version' ) );
}

Now the version defined in style.css will be used for the ver URL parameter when style.css is loaded.

Other CHILD_THEME_ Constants

You can also define Genesis’s CHILD_THEME_NAME and CHILD_THEME_URL (these values are used in the default Genesis footer) based on the header values in style.css.

if ( ! defined( 'CHILD_THEME_NAME' ) ) {
    define( 'CHILD_THEME_NAME', wp_get_theme()->get( 'Name' ) );
}

if ( ! defined( 'CHILD_THEME_URL' ) ) {
    define( 'CHILD_THEME_URL', wp_get_theme()->get( 'ThemeURI' ) );
}

You can see this code being used in my Bootstrap 4 Genesis starter theme.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Draft, Programming, Solution Tagged With: cache, CSS, Genesis, WordPress Theme

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in