LoginSignup
0
0

More than 1 year has passed since last update.

WordPressで特定の固定ページをスラッグかIDを元に複製する方法

Last updated at Posted at 2023-01-18

例えば、「会社概要」の固定ページがあったとして、新しく作るページにも「会社概要」と同じ内容を表示したい場合の方法です。

こうすることで、1つの固定ページを編集すれば、複製した固定ページにも反映されます。

<?php
  get_header();

  // $page = get_page_by_path('sample/sample');  // スラッグ指定(階層指定も可能)
  $page = get_post('〇〇'); // id指定
  $page_content = $page -> post_content;  // 本文を取得
  // ショートコードを使っている場合は置換
  $page_content = str_replace('[tempurl]', esc_url(get_template_directory_uri()), $page_content);
  echo $page_content;
  
  get_footer();
?>
0
0
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
0
0