Robin
Robin

Reputation: 87

How to display page content in custom theme in wordpress?

I have been searching for this a few hours now and I might just overlook it or asking the wrong questions in google, but I would really like to know how I can get the content I type in e.g. the About page in the WordPress dashboard, to display on my page.php.

Upvotes: 0

Views: 2822

Answers (2)

Mathew Tinsley
Mathew Tinsley

Reputation: 6966

You can get the content of any arbitrary page like this:

$page = get_page_by_title('About');

I'm grabbing the page by the title, you can also get it by ID or URL path

You can then display it by outputting the post_content property of the post object. Note that if you need it to be formatted, you'll need to apply the the_content filter:

echo apply_filters('the_content', $page->post_content);

Upvotes: 1

Mihai Zinculescu
Mihai Zinculescu

Reputation: 389

If you need to show a specific post/page by id, Wordpress has the function

<?php get_post( $id, $output, $filter ); ?> 

Documentation here: https://codex.wordpress.org/Function_Reference/get_post

Upvotes: 1

Related Questions