When designing a client site, you might like to have a snippet of content somewhere that the client can edit themselves. It might be a “Specials Box” or the Header welcome text, or a Footer “Contact Us” details section. Rather than hard code this into the template, you should create a PAGE with that content, then call the content by ID from your PHP code in the template files.

The PHP code to pull out and display the content by Page ID is as follows :

$post_id = 69;     // Your Page ID Here
$queried_post = get_post($post_id);
$content = $queried_post->post_content;
$title = $queried_post->post_title;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo "<h1>".$title."</h1>";
echo $content;

That’s it!

Make sure you use this best practice for any client site, and ensure as much of the site text is editable by the client themselves using this method.

Alternatively, you can create custom fields in the SETTINGS area but I find the PAGES method described here much more portable for the future if you ever design to change templates.

You must be logged in to post a comment.