Skip to content

functions.phpについて

T. Kameda edited this page Feb 6, 2018 · 2 revisions

functions.php は、基本的に「設定」を行う場所。

アップデートのためのライブラリの読み込みと、設定

require 'plugin-update-checker/plugin-update-checker.php';
$MyUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
	'https://raw.githubusercontent.com/toiee-lab/kanso-general/master/theme.json',
	__FILE__,
	'kanso-general'
);

このテーマの最新バージョンとダウンロードURLを書いたファイルを、Githubにホスティングしている。そのURLなどを設定するだけで、アップデートが動くようになる(ありがとう、 plugin-update-checker)

kanso_general_setup

if ( ! function_exists( 'kanso_general_setup' ) ) :
	/**
	 * Sets up theme defaults and registers support for various WordPress features.
	 *
	 * Note that this function is hooked into the after_setup_theme hook, which
	 * runs before the init hook. The init hook is too late for some features, such
	 * as indicating support for post thumbnails.
	 */
	function kanso_general_setup() {
		/*
		 * Make theme available for translation.
		 * Translations can be filed in the /languages/ directory.
		 * If you're building a theme based on kanso-general, use a find and replace
		 * to change 'kanso-general' to the name of your theme in all the template files.
		 */
		load_theme_textdomain( 'kanso-general', get_template_directory() . '/languages' );

function_exists をかけている理由は、子テーマで上書きできるようにするため。 kanso_general_setup メソッドの中で、いろんな設定をしている。

メソッドを調べる

その他

いろんなファイルを読み込んだりする。

ウィジェットなどを別のファイルで作成しているので、それを読み込むことで使えるようにしている。