LoginSignup
2
2

More than 5 years have passed since last update.

WordPress のテーマ情報の取得

Last updated at Posted at 2016-07-13

wp_get_theme()

テーマ情報取得の関数。テーマの style.css に書かれているメタ情報を取得できる。
戻り値は WP_Theme オブジェクト。

wp_get_theme.php
<?php
$my_theme = wp_get_theme();

// Echo the name of the current active theme.
echo $my_theme; // wp_get_theme()

// Display the Current Theme's Version
echo $my_theme->Name . " is version " . $my_theme->Version;

// Display the Current Theme Author URI
echo $my_theme->{ 'Author URI' };
// Or,
echo $my_theme->get( 'AuthorURI' );

// Get Other Data: Text Domain & Theme URI
echo $my_theme->get( 'TextDomain' );
echo $my_theme->get( 'ThemeURI' );

で何が便利なの

テーマにスタイルシートや JavaScript ファイルを埋め込むには wp_enqueue_style() あるいは wp_enqueue_script() を使います。

どちらもバージョンの引数を指定できますが、指定しないと WordPress のバージョンが使われます。
まぁ、スタイルシートのテーマバージョンを更新した時にPHPも直すのが面倒って時に便利。
(なにゆえバージョンをちゃんと指定するかは公式テーマだったり、キャシュ関係とか)

という実装を Iemoto でしています。

https://github.com/megumiteam/iemoto/blob/master/root/functions.php#L110
(grunt-init テンプレートなのでよしなに置き換えてください)

git のバージョン番号とかにしたいってときは以下を参考に
https://memo.dogmap.jp/2015/02/27/wordpress-git-commit-id-to-theme-version/

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2