LoginSignup
6
5

More than 5 years have passed since last update.

WordPressのフロントページに設定したページのIDを取得

Posted at

特定の固定ページの情報を取得する場合、次のようにget_page_by_pathを使うことができます。

$page = get_page_by_path('company');  // スラッグが companyの固定ページを取得

しかし、固定ページを「フロントページ」に設定している場合、スラッグが存在しないためこのファンクションが使えません。といって、「by_path」というファンクション名に惑わされて、次のように指定しても正常に動作しません。

$front_page = get_page_by_path('/'); // 悪い例

正解は、get_optionを使って、次のように取得するようです。

$front_page_id = get_option( 'page_on_front' ); // IDのみが取得される

get_optionでは、この他にもさまざまな情報が取得できるようです。

6
5
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
6
5