Using WordPress Post Meta Data to Manipulate Page Sub Headings
Using WordPress post meta data sounds a little daunting at first, but check out this simple example and you’ll soon get the hang of it.
You want your page sub heading to be different to your page title but its all done in the theme. Plus, you want to control it from the admin panel.
Find the “Custom Fields” section of your page in the admin.
Under the “Add New Custom Field” bit, click “Enter New”.
For “Name” lets call it “Alt_Page_Sub_Head”.
For “Value” lets call it “My New Alternative Page Sub Heading”. (or anything you want)
WordPress Post Meta Data
Now in the theme’s page template find where the page title is called, comment it out and do this instead.
<header class="page-entry-header"> <!-- <h1 class="entry-title"><?php the_title(); ?></h1> --> <?php $Alt_Page_Sub_Head = get_post_meta($post->ID, 'Alt_Page_Sub_Head', true); ?> <h1 class="entry-title"><?php if ($Alt_Page_Sub_Head) { echo $Alt_Page_Sub_Head; } else { the_title(); }; ?></h1> </header>
Line 2 is commented out as it just calls the page title.
Line 3 reads the post meta data into a variable.
Line 4 uses the post meta data as our sub heading, if it doesn’t exist we simply fall back to the page title.
You don’t just have to use it for replacing page sub headings you can use it for all kinds of cleverness.
Have fun.