While the information in this tutorial will be focused on excerpts and taxonomies, the big change in WordPress 2.9 is that the meta box functions have been included in a new file: /wp-admin/include/meta-boxes.php. This change allows us to do some fun things because the code is not limited to a single area anymore.
In this tutorial, you’ll learn how to utilize the add_meta_box() functionality to add two things to your pages:
- Excerpt box.
- Custom taxonomies boxes.
Being able to add these meta boxes to pages isn’t the limit. This tutorial should serve as a starting point. You could do the same for custom post types, links, or anything that fires the do_meta_boxes action hook.
Adding an excerpt box to your page editor
The first thing you should do is open your theme’s functions.php file in your favorite text editor. Paste the following PHP code into it:
add_action( 'admin_menu', 'my_page_excerpt_meta_box' );
function my_page_excerpt_meta_box() {
add_meta_box( 'postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'page', 'normal', 'core' );
}
Now, you’ll be able to add excerpts to your pages, just like posts. This can come in handy with themes that display search results in excerpt form.
Adding custom taxonomies to your page editor
This one will be a bit trickier. I’ll have to assume you’ve created a custom taxonomy specifically for pages. If you’re unfamiliar with this process, you need to familiarize yourself with creating custom taxonomies.
Let’s assume you’ve created a “People” taxonomy for pages. Your custom taxonomy code should look a little like this.
register_taxonomy( 'people', 'page', array( 'hierarchical' => false, 'label' => 'People', 'query_var' => true, 'rewrite' => true ) );
The important thing in that line is page. We’ll be adding meta boxes for all taxonomies that have been registered for pages.
Again, we’ll go to our theme’s functions.php file. Paste this PHP code in:
add_action( 'admin_menu', 'my_page_taxonomy_meta_boxes' );
function my_page_taxonomy_meta_boxes() {
foreach ( get_object_taxonomies( 'page' ) as $tax_name ) {
if ( !is_taxonomy_hierarchical( $tax_name ) ) {
$tax = get_taxonomy( $tax_name );
add_meta_box( "tagsdiv-{$tax_name}", $tax->label, 'post_tags_meta_box', 'page', 'side', 'core' );
}
}
}
Once that’s done, you’ll be able to use your page-based custom taxonomies.
Please note that hierarchical taxonomies aren’t going to be available yet. Maybe in WordPress 3.0?
A good move by WordPress
I’m glad WordPress is moving in this direction with some of its functionality. Average Joe might not realize the implications of something as simple as moving code to another file, but developers should rejoice. The reuse of code is a cornerstone of good development practice. By making things more modular, it becomes easier to create new things without rewriting a lot of code.
I’ve shown you how to do these things with pages. Just imagine being able to make these simple and quick changes for custom post types (i.e., content types), essentially having the ability to create any type of site you want with WordPress.

This is awesome! I just created “person” taxonomies in a photo blog I started for myself, so I could add in people tagged before guest’s can tag themselves.
Great post. Especially the excerpt box for pages. I was looking for this as I use Wordpress mainly as a CMS.
Just one question. Are excerpts for pages only possible in WP 2.9 ?
The Frosty — Sounds cool. I’m just trying to thing of a reason to play around with this feature.
Edwin — Excerpts for pages using the method shown above are only possible in WordPress 2.9+. But, there are some plugins that allow you to do this now.
So – this is interesting. But what if I wanted to create a single taxonomy for pages AND posts? Is it an either/or proposition at the moment?
John — Here’s an example of adding the taxonomy for both
postandpage:Justin, just getting started with custom taxonomies. Did you write that tutorial about how to use taxonomies to make custom template by taxonomy? I definitely have use for that one.
Thanks Justin for great writeup. This has huge potential for pages. One thing. Does 2.9 enable us to filter query_posts by multiple taxonomies? (i.e., like you can do with tags). I did see one plugin for this, but have not tested.
http://scribu.net/wordpress/query-multiple-taxonomies/qmt-1-0.html
Hi Justin, Thanks for share info! Do you know how can i insert a custom taxanomy from an external form? like wp_insert_post for posts or add_post_meta for custom fields.
Thanks for all of the tutorials. I have a similar question to Juani. If I wanted to add custom taxonomies to posts in bulk, what’s the best way to do this? I’ve been looking at the wp_add_post_tags function, but it doesn’t seem like there’s any way to change this to use your custom taxonomy instead of post_tag
The only thing I’ve been able to think of is a rather tedious process of going directly to the database to get a list of posts, then inserting records into the term_relationships table
Justin – Re: my question above about filtering multiple taxonomies with query_posts, I can confirm this plugin does the trick. Just wish this was already in core…
http://scribu.net/wordpress/query-multiple-taxonomies/qmt-1-0.html
2.9 already?. I now using 2.7….But thank for tutorial, It’s really help.
Currently i am using Drupal evaluating Wordpress for some of my blogs, Drupal has taxonomy module for working with tagging wondered how to do it it word press, your post helped me with it.
Hey, Pardon me… what are excerpts and taxonomies actually?
Yep, cant wait for 2.9 version
greeting, darila
Hi Justin,
Do you know how to use custom taxonomy with wp_insert_post ?
Thanks in advance,
Nick
Thanks a lot for this and the “Custom taxonomies” tutorials, you just saved me hours of work!
Thanks, i was needing info how to add excerpts to pages. Nice post.
greetings, nagradne igre
All I can say is that Wordpress is number 1 for me and I’ve been using it for my small online business. Everything works fine particularly on excerpts and taxonomies. Thanks.
Thanks for u tutorial Justin, I love reading ur blog since it always contain a great article inside. Keep sharing bro, nice to know u.
Justin,
If I add a taxonomy for BOTH page and post, using:
register_taxonomy( ‘people’, array( ‘post’, ‘page’)…..
Can I create an archives page that lists both pages and posts with that term?
Specifically, I will assign a person’s name to posts in our blog and to pages. When someone clicks on one of the names, I want an archive page with both posts and pages listed.
Thanks! And fantastic articles you’ve written on this subject.
Thanks a lot for tutorial, recently I had a problem with excerpts. Fortunately, I got the answer here. Thanks
Currently i am using Drupal evaluating Wordpress for some of my blogs, Drupal has taxonomy module for working with tagging wondered how to do it it word press, but this post helps a lot in conceptual idea I should use to get it done.
it looks like adding excerpts just got easier: `add_post_type_support( ‘page’, ‘excerpt’ );` and you’re set.
what would be the easiest way to add the post tags to pages though?
Now i know the way to make excerpts box thanks to you. hope you post another useful tips for us.
Thanks a lot for this and the “Custom taxonomies” tutorials, you just saved me hours of work!