[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 );

view raw

gistfile1.php

hosted with ❤ by GitHub


Posted

in

by

Tags:

Comments

“[WordPress] git 管理しているテーマで git のコミットIDをバージョン番号として使用するサンプル”. への1件のコメント

  1. gatespace のアバター

    せんせい、4行目に閉じカッコが足りないよ

    if ( file_exists( $stylesheet_dir.’/.git/HEAD’ ) ) {

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト /  変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト /  変更 )

%s と連携中

%d人のブロガーが「いいね」をつけました。