拡張関数
テンプレートが追加している関数です。include/functions.phpとinclude/acf.phpにあります。
アセット
loadScript
loadScript(string $name, string $path, array $dependencies = [], ?string $version = null, array|bool $args = []): void
wp_enqueue_script()のラッパーです。$pathが相対パスなら、テーマのディレクトリからのパスとして扱います。$versionが空なら、config.phpのバージョン番号を使います。
$argsはwp_enqueue_script()の$argsです(例:['strategy' => 'defer'])。true/falseを渡すと、フッターに出力するかどうかの指定として扱います。get_header()より前に呼んでください。アセットファイルの読み込みを参照してください。
loadStyle
loadStyle(string $name, string $path, array $dependencies = [], ?string $version = null): void
wp_enqueue_style()のラッパーです。$pathと$versionの扱いはloadScript()と同じです。
get_asset_url
get_asset_url(string $path, ?string $version = null): string
テーマ内のファイルのURLに?v={バージョン}を付け、エスケープして返します。$versionが空なら、config.phpのバージョン番号を使います。
the_asset_url
the_asset_url(string $path, ?string $version = null): void
get_asset_url()の結果を出力します。
get_file_version
get_file_version(): string
アセットのURLに付けるバージョン番号を返します。config.phpで定義しています。アセットの変更を公開するときは番号を上げてください。
カスタムフィールド
どの関数も、カスタムフィールドのプラグインが無効なときはエラーにならず、何も返しません。
_get_field / _the_field
_get_field(string $selector, mixed $post_id = false, bool $format_value = true): mixed
_the_field(string $selector, mixed $post_id = false, bool $format_value = true): void
get_field()とthe_field()を、プラグインが無効でも使えるようにしたものです。
the_simple_field
the_simple_field(string $key, mixed $post = null, string $default = ''): void
フィールドの値をエスケープし、改行を<br>に変えて出力します。値が空なら$defaultを出力します。
YouTube
get_youtube_url(string $key, mixed $post = null): ?string
get_youtube_id(string $key, mixed $post = null): ?string
get_youtube_loop(string $key, mixed $post = null): ?string
YouTubeの動画を入れたoEmbedフィールドから、埋め込み用のURL、動画のID、ループ再生のパラメータを付けた埋め込み用のURLを返します。the_youtube_url()とthe_youtube_loop()は結果を出力します。
その他
get_page_slug
get_page_slug(int|WP_Post|null $page_id = null): string
ページのスラッグを、親ページのスラッグと-でつないで返します。/company/access/ならcompany-access、トップページならindexです。ページのProjectのクラス名を付けるときに使います。
is_new
is_new(int|WP_Post|null $post = null, int $gap = 2): bool
記事が$gap日以内に公開されたかどうかを返します。$postを省略すると、ループ中の記事を調べます。
is_mobile
is_mobile(): bool
ユーザーエージェントがスマートフォンかどうかを返します(iPadは含みません)。レイアウトの切り替えにはメディアクエリを使い、この関数は出力する内容自体を変える必要があるときだけ使います。
remove_line_break
remove_line_break(string $text): string
改行と、各行の先頭と末尾の空白を取り除きます。
get_setting_files
get_setting_files(string $dir): string[]
settings/{$dir}/にあるPHPファイルを、名前が_で始まるものを除いて返します。include/で定義のディレクトリを読み込むときに使います。
ショートコード
include_template
[include_template slug="templates/contact-banner"]
get_template_part()を使って、本文の中にテンプレートの部品を表示します。共通コンポーネントを参照してください。