Back to Blog

WordPressでテーマのバージョンを出す関数

WordPress

2024/03/21

functions.php


/**
 * テーマバージョン表示
 */
function version_num() {
	if ( function_exists( 'wp_get_theme' ) ) {
		$theme_data = wp_get_theme();
	} else {
		$theme_data = wp_get_theme( get_theme_file_path() . '/style.css' );
	}
	$current_version = $theme_data['Version'];
	return $current_version;
};

使い方

<?php wp_enqueue_style( $handle, $src, $deps, version_num(), $media ); ?>

実際には

<?php wp_enqueue_style( 'top', get_theme_file_path() . '/css/top.css', array(), version_num(), 'all' ); ?>

Related Posts