Child Theme (extended)

More from this category




Twenty Twenty Child – with additional css for versioning – cache busting

be sure to update the enque for sub-style sheet – this version – the filetime works better.
[code style=”php”]

/*//// updated way to use filetime //////*/
function smp_versioned_style()
{
wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() .’/css/sword_style.css’, array(), filemtime(get_stylesheet_directory() .’/css/sword_style.css’), ‘all’ );
}

add_action( ‘wp_enqueue_scripts’, ‘smp_versioned_style’, 999 );

[/code]




twentytwenty-additional-css


twentytwenty-child-master


twenty-twenty-child-simple


twentytwenty


https://wordpress.stackexchange.com/questions/145141/attributing-a-version-number-to-a-child-themes-main-stylesheet
You can update the version in the child themes style sheet itself…

[code style="css"]
/
Theme Name: Twenty Fourteen Child
Theme URI: http://example.com/twenty-fourteen-child/
Description: Twenty Fourteen Child Theme
Author: John Doe
Author URI: http://example.com
Template: twentyfourteen
Version: 1.1.2 <—- Update here
/
[/code]


This code would be added in your child theme’s functions.php and what it does is re-registeres the child theme with the current style.css version number so whenever you make changes to your child theme you can update your version number and it will update the ?v= parameter in the style.css URL to prevent browser caching.

[code style="php"]
add_action( ‘wp_enqueue_scripts’, function() {

if ( ! defined( 'WPEX_THEME_STYLE_HANDLE' ) ) {
    return;
}

// First de-register the main child theme stylesheet
wp_deregister_style( WPEX_THEME_STYLE_HANDLE );

// Then add it again, using filemtime for the version number so everytime the child theme changes so will the version number
wp_register_style( WPEX_THEME_STYLE_HANDLE, get_stylesheet_uri(), array(), filemtime( get_stylesheet_directory() . '/style.css' ) );

// Finally enqueue it again
wp_enqueue_style( WPEX_THEME_STYLE_HANDLE );

} );
[/code]

More from this category




https://kinsta.com/blog/wordpress-child-theme/

You’ve been running your WordPress site for a while and it’s been doing what you need it to. But now, you decide you need to customize it.

Or maybe you’re creating your site with a theme you’ve downloaded from the theme directory or one you’ve bought, and you realize it doesn’t work in exactly the way you need it to.

What do you do, then?

You can either find a plugin that will provide the customization you need or switch to a new theme. But what if you’re happy with your current theme and can’t find a plugin that adds what you need in terms of functionality?

Answer: you’ll need to customize your theme. And best practices say: you do that via (WordPress) child themes.

In this post, I’ll show you exactly how to create a child theme in WordPress, how to use it to customize your site, and how child themes work. I’ll also explain the concept of parent themes and describe how the parent theme on your site interacts with a child theme:

Scroll to Top