Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Last active November 24, 2015 03:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wokamoto/048b93a4c87b86b184d6 to your computer and use it in GitHub Desktop.
Save wokamoto/048b93a4c87b86b184d6 to your computer and use it in GitHub Desktop.
[WordPress] git 管理しているテーマでバージョンとして git のコミットIDをバージョン番号として使用するサンプル
<?php
$version = 'default';
$stylesheet_dir = get_stylesheet_directory();
if ( file_exists( $stylesheet_dir.'/.git/HEAD' ) ) {
$head = explode(' ', trim(file_get_contents($stylesheet_dir.'/.git/HEAD')) );
if ( isset($head[1]) && file_exists($stylesheet_dir.'/.git/'.$head[1]) ) {
$version = trim(file_get_contents($stylesheet_dir.'/.git/'.$head[1]));
}
}
define( 'THEME_VERSION', $version );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment