0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WordPressで他のページのコンテンツを挿入する

Posted at

WordPressサイト構築のさい、他のページのコンテンツを挿入したくなることがあります。
テンプレートに記述する場合はこんな感じ。

$post = get_page_by_path('slug');
$content = $post->post_content;
echo $content;

Advanced Custom Fieldsのデータを挿入したいとき。

$post = get_page_by_path('slug');
$content = get_field('field_name', $post->ID);
echo $content;

テンプレートではなくエディタで記述する場合はショートコード化。

functions.php
function function_name()
{
	$post = get_page_by_path('slug');
	$content = $post->post_content;
	return $content;
}
add_shortcode('shortcode_name', 'function_name');

Advanced Custom Fieldsのデータをショートコードで挿入することもできます。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?