Warning: Undefined array key 2 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 15
Warning: Undefined array key 3 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 18
Warning: Undefined array key 4 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 21
Warning: Undefined array key 2 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 27
Warning: Undefined array key 3 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 30
Warning: Undefined array key 4 in /home/c3937730/public_html/dubdesign.net/wp-content/themes/sango-theme-poripu/library/functions/prp_content.php on line 33
WordPressをカスタマイズしていく際、テーマのfunctions.phpが見やすいよう、部分部分で各コードを外部ファイルにして、functions.phpにインクル(含ませる)させておくと便利です。
かかかず
スッキリして、更新もしやすくなります。
functions.phpに記述するコード
function.php に読み込ませる場合、「親テーマのディレクトリを参照するのか?」「子テーマのディレクトリを参照するのか?」によって記述するコードが多少異なります。
親テーマのディレクトリ構造内に存在するファイルをインクルードする場合は、get_template_directory() を使ってパスを取得します。
functions.php
require get_template_directory() . '/functions/jscss/functions-jscss.php'; // 親テーマの外部ファイルを読みませる場合
require_once get_stylesheet_directory() . '/functions/php/prp_init.php'; // 子テーマの外部ファイルを読み込ませる場合
一方、子テーマのディレクトリ構造内に存在するファイルをインクルードする場合は、get_stylesheet_directory() を使います。
外部ファイルの記述方法
記述は、基本的にfunctions.phpへ書く時と同じ内容で問題ありません。
functions.php
<?php
// 読み込みたいコードを記述
?>
上記のように、<?php 〜〜〜 ?> の中にコードを書いて保存すればOKです。


