Find a Parent Theme’s stylesheet $handle when it registers a stylesheet

To clarify this, for anyone using Divi theme (but generally any WP theme), a simple inspection using Dev tools on the “head” for the stylesheet links usually gives a clue about the handle, as Den Isahac mentioned previously (it wasn’t clear as he mentioned it can’t be found).

Anything before the “-css” on the ID of the link for the stylesheet of the Parent theme is generally that handle.

Example below with Divi, id=”divi-style-css” thus $handle=”divi-style”

Above is template style with id='divi-style-css' , and below the child

Thus for Divi, you would enqueue theme like this:

<?php
function my_theme_enqueue_styles() {

    $parent_style = "parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>

Little bonus:
Browsers have an annoying tendency of caching the child stylesheet depending on its “Version”. The drawback is that it prevents you from ever seeing your edits even after refreshing / clearing cache, unless you change the “Version” number in your css file after every edit.

You can change this behavior by swapping wp_get_theme()->get(‘Version’) (the $ver parameter) for the handy filemtime( get_stylesheet_directory() . ‘/style.css’ ) instead, which adds a version number after the stylesheet corresponding to the timestamp from the last time you saved your child stylesheet, instead of the true “Version” declared in that stylesheet. You can eventually revert to the regular function before going live, but it can be extremely helpful during production.

The whole enqueue script for Divi would thus become:

<?php
function my_theme_enqueue_styles() {

    $parent_style="divi-style"; // This is 'Divi' style referrence for the Divi theme.

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        filemtime( get_stylesheet_directory() . '/style.css' )
    );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>