Skip to main content

Creating Pages

Don't create pages on the admin screens. Define them in settings/pages.php and add a template for each.

Defining pages​

// settings/pages.php
return [
'company' => [
'title' => '会社案内',
'seo' => ['description' => '会社概要とアクセス'],
],
'company/access' => ['title' => 'アクセス'],
'contact/result' => [
'title' => '送信完了',
'seo' => ['noindex' => true],
],
'old-page' => ['status' => 'trash'],
];
  • Keys are page paths. Write a child page as parent/child.
  • title, menu_order and template are used only when the page is created.
  • status => 'trash' moves the page to the trash. It is never deleted permanently.
  • seo holds the page's SEO settings (title / description / ogImage / noindex / nofollow / canonical). See SEO.

The next time an administrator opens the admin screens, only the pages that don't exist yet are created.

  • The title and content of existing pages are never changed, so editors can update them freely.
  • A page removed from the definitions is not deleted. The Pages screen shows a notice instead, and has a re-sync button (「再同期」).

Page templates​

Name the template after the page path: page-{slug}.php. For a child page, join the parent and child slugs with __.

http://example.com/company/
-> page-company.php

http://example.com/company/access/
-> page-company__access.php
warning

WordPress also uses page-access.php for /company/access/, but always include the parent slug (page-company__access.php). It's easier to find the template from the URL, and two pages with the same slug under different parents get separate templates.

Pages without a template of their own use page.php, which shows the content entered on the admin screens.

CSS​

Follow the CSS methodologies in WordPress templates too. Name the project file and class after the page path.

http://example.com/company/
-> page-company.php
-> data/scss/object/project/company/_index.scss
-> .p-company

http://example.com/company/access/
-> page-company__access.php
-> data/scss/object/project/company/_access.scss
-> .p-company-access
info

See also the Project file naming rules. get_page_slug() returns the page path joined with - (company-access).