Get parent theme version

Question

How do I get the parent theme’s version in a child theme?

I want to use it when loading the parent theme’s stylesheet.

Here’s how I load the stylesheets in the child theme’s function.php file:

function sometheme_enqueue_styles() {

  // Get parent theme version
  $parent_theme_version = wp_get_theme()->parent()->get( 'Version' );

  // Load parent theme stylesheet
  wp_enqueue_style( 'sometheme-style', get_template_directory_uri() . '/style.css', array(), $parent_theme_version );

  // Load child theme stylesheet
  wp_enqueue_style( 'sometheme-child-style',
    get_stylesheet_directory_uri() . '/style.css',
    array( 'sometheme-style' ),
    wp_get_theme()->get('Version')
  );

}
add_action( 'wp_enqueue_scripts', 'sometheme_enqueue_styles', 11 );

However, this will use the child theme’s version for both stylesheets…

I have also tried this:

$parent_theme = wp_get_theme('sometheme');
$parent_theme_version = $parent_theme->get( 'Version' );

…and this:

$parent_theme = wp_get_theme(get_template());
$parent_theme_version = $parent_theme->get( 'Version' );

But again, the parent theme version keeps getting the version from the child theme.

0
transbetacism 2 years 2020-12-18T09:10:27-05:00 0 Answers 10 views 0

Leave an answer

Browse
Browse