8 useful code snippets to get started with WordPress 3.0

WordPress 3.0, scheduled to launch May 1st, 2010, will be a real revolution for the blogging system. With new functionalities such as custom post types, developers will be able to create more complex and more powerful sites based on WordPress. In this article, I have compiled the most useful resources to get you started with WordPress 3.0.

How to create a custom post type

Custom post type are an incredible step forward for WordPress, because it will allow developers to create post types according to their needs.
For now, we have posts, and pages. With WordPress 3.0, we’ll be able to create a new post type called products, where a client can sell his products only, while regular post for his blog.

Creating a custom post type is easy: All you have to do is to open your theme functions.php file and paste the following:

$args = array(
        'label' => __('Products'),
        'singular_label' => __('Product'),
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'page',
        'hierarchical' => false,
        'rewrite' => true,
        'query_var' => 'products',
        'supports' => array('title', 'thumbnail')
register_post_type( 'product' , $args );

Once you saved the file, login to your WordPress dashboard and have a look at the navigation on the left: A new post type, named Products, has been added.
Source: http://codex.wordpress.org/Function_Reference/register_post_type

Custom post types with custom taxonomies

In the previous example, I’ve shown you how to create a custom post type, which is pretty useful to use WordPress as a real CMS and not a simple blog publishing platform.

Now, let’s see something a little bit more complex, but extremely interesting: Creating a custom post type associated with custom taxonomies. For those who don’t know, a taxonomy is a term (such as category, tag or anything else) related to posts. For more information about taxonomies, you should have a look at WordPress Codex.

In this example, we’ll create a custom post type named Albums, which belong to “Genres” (the custom categories) and have “Performer” as tags. This snippet has to be pasted in your functions.php file. With those 27 lines of codes, you can create a fully functional music albums archive. Ain’t that powerful?

function post_type_albums() {
                     array('label' => __('Albums'),
                             'public' => true,
                             'show_ui' => true,
                             'supports' => array(
// Adding the Custom Taxonomy for Genres. Here we can create categories specific for this post type.
	register_taxonomy( 'genres', 'albums', array( 'hierarchical' => true, 'label' => __('Genres') ) );

// Adding the Custom Taxonomy for Performer. Here we can add tags specific for this post type.
        register_taxonomy( 'performer', 'albums',
                         'hierarchical' => false,
			 'label' => __('Performer'),
			 'query_var' => 'performer',
			 'rewrite' => array('slug' => 'performer' )
add_action('init', 'post_type_albums');

Source: http://wpspecial.net/2010/03/how-to-add-custom-post-types-in-wordpress/

Query custom post types

Now that you’ve learned how to create custom post types, the next step is to learn how to retrieve them from the WordPress database and display it on your blog.

Good news for developers, there’s nothing hard or new in the process. Custom post types can be retrieved easily, using the WP_Query object.
The following example will create a custom loop which will get only the albums custom post type.


<?php global $wp_query;
$wp_query = new WP_Query("post_type=albums&post_status=publish");

while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>

Enable multisite feature

One of the most exiting new feature of WordPress 3.0 is definitely multisite management. In brief, with a single installation of WordPress you’ll be able to run a network of WordPress blog. How cool is that?

To take advantage of this feature, simply paste the following line of code in your wp-config.php file. This file is located at the root of your WordPress install.

define('WP_ALLOW_MULTISITE', true);

As andrea_r pointed out, once you added the code above, you have to visit Tools -> Network and set up the network.
Source: http://wptheming.com/2010/03/wordpress-3-0-enable-network/

Custom author profiles

Most of the top blogs of the industry do not have a single author but a team of different contributors. WordPress allows you to create author pages, but WordPress 3.0 is introducing a new function which will allow you to use different templates for different authors, like we can currently do with categories.

All you have to do is to create an author page named author-XX.php where XX is either the author ID or nicename. For example, if your user nicename is “john”, you’ll have to call the file author-john.php.

Source: http://codex.wordpress.org/Function_Reference/get_author_template

Add custom backgrounds

WordPress 3.0 is introducing a new feature that will for sure be loved by non tech-friendly users: Custom background. The feature allows the user to upload a background in his WordPress dashboard, specify its position, and automatically have it added to his blog.

Of course, the theme used by the blogger has to support this feature, otherwise the uploaded background will not be visible. To do so, simply open your functions.php file and paste the following line:


Style WordPress editor using CSS

WordPress features a WYSIWYG editor, which allow you to see text in bold, italic, and so on. But some people want more, such as being able to visualize their blog post in the blog font and colors.

This new feature allows you to create a css file (named editor-style.css in the example below) and link it to the editor for a better WYSIWYG rendering. Simply paste this code snippet to your functions.php file.

add_filter('mce_css', 'my_editor_style');
function my_editor_style($url) {
  if ( !empty($url) )
    $url .= ',';
  // Change the path here if using sub-directory
  $url .= trailingslashit( get_stylesheet_directory_uri() ) . 'editor-style.css';

  return $url;

Source: http://azaozz.wordpress.com/2010/01/02/can-themes-style-the-visual-editor/

Make your theme compatible with WordPress 3.0 menus

WordPress 3.0 is going to feature a totally new menu system, which will allow users to add only the desired pages, add categories, and more. Good news for theme developers; adding WP 3.0 menu support to your themes is extremely easy.

To do so, open functions.php and add the following line:

add_theme_support( 'nav-menus' );

Once added, you can use the brand new wp_nav_menu() function in your theme files:


As you can see, it accepts the same kind of parameters than the good ol’ wp_list_categories() function.
Source: http://wpspecial.net/2010/04/menu-support-for-wordpress-3-0-themes/

  • Nice!

    I liked the 3.0 menus functions and the multisite define code 😉


    • I am just waiting for May 1st to try my hands on the actual WordPress 3.0 public release !

      • Oh, is it not released yet? After reading this article I am dying to use it, LOL. I especially look forward to the custom taxonomies and custom author profile features.

  • Amazing stuff 🙂 thank you so much for sharing the informative article.

  • Time to start converting my older WordPress site to 3.0. Thanks for the post!

  • Curios whether the menu-thing will be really better, ’cause the current one sucks…especially when you want to highlight the parent menu.

    Thanks for the round-up…

  • Seems great. Eagerly waiting for WP3.0. Custom post type is awesome. 🙂

  • Thanks for the summary – but why are you using the following code in the example #1: register_post_type( ‘album’ , $args ); – shouldn’t it be register_post_type( ‘Products’ , $args ); ?

  • And once you enable multi-site you still have to visit Tools -> Network and set up the network. Won’t work until you do. 😉

  • Pingback: === popurls.com === popular today()

  • Thanks for this. I’m working on releasing a theme and going to finish it just before wp 3.0 comes out. It helps to have forward compatibility built in with an untimely release.

  • Thanks! Very useful!

    This one is also handy: enable buddypress on all the blogs
    define ( ‘BP_ENABLE_MULTIBLOG’, true );

  • For styling the editor, the mce_css has been around for a while now. What is new in 3.0, though, is a shortcut function, add_editor_style(). When called alone, it’ll simply try to use editor-style.css, though it could instead take an argument of your own CSS filename if you prefer.

  • Multisite function FTW! Although WordPress Mu would be the best way to go about this IMO.

  • Jean-Baptiste,
    Great post. These are some helpful tips.
    I want to set up the Author Profiles on my blog. I also have a few smaller blogs that I want to bring into my base installation. This will make updates more simple.

  • Nice collection of resources here! Does anyone know where to find information about setting custom meta boxes on the custom post types? That’s the one piece of the puzzle I haven’t been able to solve yet.

    • Hello Devin! Thanks for the compliments. I haven’t found anything about it, though I definitely should try to do it by myself if I have some spare time. Please let me know if you find anything about it 🙂

  • Drupal had the multi site on multi domains for years.

    Problem is, as you increase the amount of Drupal websites it just got slower.


  • I’m really looking forward to WP3.0 with some of these features, especialy the custom post types. One thing I notced when playing around is that when I first set it up (using pretty permalinks) I needed to resubmit the permalinks to update the htaccess file. Without it, my custom pages where always giving a 404

    Also on a side note, the name field in comments is too short, My name is “Damian Jakusz-Gostomski” and it can’t fit 🙁

    • That’s good to know! WP 3.0 is beta for know, so hopefully they’ll have the problem fixed for the release!
      Regarding your name, I edited it. Sorry for the inconvenience.

  • Oh, its wonderfull, it will help me to solve some problems in my SEO work, thank you for article.

  • Understandably when it’s still beta, code resources thin on the ground for 3.0 so this is very helpful, thanks! Trying to build using 3.0 now that bit easier. Custom post types rock 🙂

  • Elliot condon

    Thank you.

    I cant wait to start making wp 3 themes.
    Bookmarked to read again later.

    Thanks again

  • Pingback: Contemplating the Tree of Woe » links for 2010-04-12()

  • Thanks so much for the article Jean-Baptiste.

    I tried out the custom post types with custom taxonomies over the weekend but struggled due to a lack of really useful information.

    I gave up for the moment due to a pressing workload but will go back to it soon with your new helpful info.

    Like Devin, I also am keen to know a bit more about custom meta boxes for my custom post types and how it all hangs together with custom taxonomies.

    Combining the three in a useful way should make a powerful CMS but I am still a little bit in the dark about how to do that in a real world environment.

    Thanks again for such helpful information.

  • By God, so many new and exciting info to digest! I didn’t know about the multisite function till you mentioned it!

  • Jean-Baptiste,

    Have you heard anything about built-in ability to style the admin area? Combined with all of these great new features, it would really solidify WP as a full-featured CMS.

    How about HTML5 support? I suppose everything is still XHTML 1.0, huh?

    AWESOME stuff here. Really looking forward to diving in head first this week.

  • Pingback: links for 2010-04-12 at DeStructUred Blog()

  • Hi,

    To add to this awesome list. There is a function in WordPress 3.0 that allows theme designers to add a login form to anywhere in the theme.
    It’s call wp_login_form()
    Check it out at http://codex.wordpress.org/Function_Reference/wp_login_form

  • Drool. I can’t wait for 3.0 to be released. Right now, we have to do a lot of hacking to the WP system to get it do what clients want it to do. But this new version will make it a breeze!

  • great post.. thanks for sharing

  • Thank you so much for mentioning two of my articles here!
    Glad that they’re helpful.

  • Thank You !

    Im planing to start a WP page, so ists very usefull

  • Pingback: Wordpress 3.0 – The new Era | Creative Cue()

  • Pingback: links for 2010-04-13 :: zota()

  • Pingback: 8 useful code snippets to get started with WordPress 3.0 | Design Newz()

  • Awesome! It sounds like some sites that don’t adapt will have issues with the release of 3.0.

  • Hi Jean-Baptiste,

    Just wanted to say thanks for another great WordPress article. I’ve learned so much from your site and get excited whenever I see new content in my feed reader.

    Thanks for all you do!

  • Yes, WP 3.0 Look better then old 2.0 m should upgrade

  • Pingback: Shared Items – 14/04/2010 | Of Penguins & Coffee()

  • Great article!
    I like your wordpress posts.

    Very useful.

  • Really cool stuff. WordPress is becoming an extremebly capable CMS. I still haven’t tried 3.0 but am going to soon. A huge draw being multi-site.

  • Pingback: Bookmarks for April 12th through April 14th – Miralize Design()

  • This is gonna be one helluva an update! Can’t wait for it to come.

  • This new set of WordPress 3.0 features combined with the new Dreamweaver CS5 capabilities will make life easier for many web developers out there. These are exciting times we live in, indeed.

  • Pingback: 8 useful code snippets to get started with WordPress 3.0 » blog.lanche86.com()

  • Pingback: links for 2010-04-15 | Evolutionary Designs()

  • Very informative article, some of the updates are long overdue.

  • Hey,
    You offer some great resources here. Thank you.

    Warm wishes,

  • There will be a lot of great new features in WP 3.0. Looks like life will be a little easier. With the new menu system, I’ll need fewer plugin…. Post type is going to eliminate all those damn custom templates I hope. I’m looking forward to trying it out. Thanks for enlightening me to some of these details.

  • Thanks for the useful codes. WordPress 3.0 does sound rather cool 😀

  • Will this be compatible with WooThemes? Or will I have to buy a new upgrade from

  • Pingback: Best On WordPress From The Past Week N.2 | wpCanyon()

  • Lisa

    Thanks for such useful information.Really appreciate all you blogs.

  • Awesome! Thanks, I can’t wait until the release of WP 3.0 to try some of these out.

  • Pingback: Make Your Theme WordPress 3.0 Compatible()

  • What should I do to show blog custom post types from users on my network (MU)?

  • Wow. Thanks for sharing this article. Very much useful! Im so much excited about WP 3.0. Thanks for posting this.

  • Excellent!

    Thank you for sharing this “post WP 3.0” article for the impatient ones 😉

  • Great stuff. Nice to read some well written posts. A long way between them. Keep it up 🙂

  • Really great, well written post, Can’t wait to try out some of the code!!!!
    Thanks for sharing.

  • Pingback: The Wordpress 3.0 functions.php File | Gilbert Pellegrom()

  • Pingback: Tornando seu tema compatível com os novos recursos do Wordpress 3 « Mateus Neves, Designer, Wordpress and more()

  • Pingback: What I’m Reading (weekly) | tj mapes()

  • Pingback: Top WordPress hacks of early 2010()

  • Pingback: links for 2010-04-26 | Folks Pants()

  • Awesome post! There are so many good things coming in WordPress 3.0 – just can’t wait to try it all. (new Custom Taxonomies FTW!)

  • MichaelH

    Under “Custom post types with custom taxonomies” that supports array should probably be:

    'supports' => array(

  • Pingback: Top Articles On The Web Design Billboard In April’10 | Showcases | instantShift()

  • Pingback: Joomla And WordPress: A Matter Of Mental Models - Smashing Magazine()

  • Pingback: Joomla And WordPress: A Matter Of Mental Models « GFX WAY()

  • Jay

    Great snippets, but “Style WordPress editor using CSS” should be shortened to add_editor_style(); 😉

    add_editor_style(); graps editor-style.css from the theme folder.

  • Pingback: Tips för dig som använder WordPress()

  • Nice update. WordPress 3.0 is a great stuff.

  • Great post! So helpful!

    Quick question on the navigation menu… With the wp_nav_menu() function is there a way to remove the wrapping tag? Similar with listing pages how you can do something like wp_list_pages(‘title_li=’)?

  • Great post! So helpful!

    Quick question on the navigation menu… With the wp_nav_menu() function is there a way to remove the wrapping ul tag? Similar with listing pages how you can do something like wp_list_pages(’title_li=’)?

    I know you can do:
    wp_nav_menu( array(‘container’ => ”) )

    And the wrapping div will be removed, but haven’t figured out how to remove that ul that gets wrapped around. Any ideas 🙂 ?

  • WordPress 3.0 here we go!nice article gives a lot of information about WP 3.0..Thanks for sharing it!

  • Is there any known reason whx the custom background does not work in a theme? I understood that you simply have to put the little line to the functions.php and that´s it? But when I try to use the custom background in my theme nothing happens. Somewhere I read that the theme shouldn´t have a CSS definition for the body background?

  • Great stuff!Thanks for sharing it.

  • Pingback: Wordpress “Snippets” « WordPress Theme Mods()

  • Thanks for sharing this great information with us. WordPress3.0 made a great step, but not as far as we expected. As long as we can custom the post type, why not split the post type to different database tables, want any update from anyone.

  • Thank you for sharing this. This will really be a big help to many.

  • Wonderful post!Do you have any idea where else can the optin box codes be placed except for theme’s sidebar? I just wonder.

  • Rob

    And here I just went and updated all my blogs and websites to 2.9.2. I always seem to be one step behind the curve. But I enjoy reading this blog and am actually looking forward to WordPress 3, which is a new one for me.

  • Jon

    I have been pretty interested in getting word press. I might start my own blog. If I do, I will defiantly use some of these snippets.


  • Pingback: Guide to Wordpress 3.0; Useful features, tips and tutorials | Nicholas Francis()

  • add_theme_support( ‘nav-menus’ );

    has changed to

    add_theme_support( ‘menus’ );

  • Pingback: Useful Resources and Tutorials to get started with WordPress 3.0 | Allweb Magazine()

  • The new menu to display both pages and categories is definitely something that was long awaiting.
    I am hoping to see something like that for widgets soon.. where the widgets can be place on specific pages.

    but i must say its kool stuff.

  • Anthony Meagher

    Hey Dominica,

    For the moment you could use the Widget Logic plugin:

  • Posted the custom background code in functions.php file in the editor and now it states:

    “Warning: Cannot modify header information – headers already sent by (output started at /home/content/89/6909389/html/wp-content/themes/ecomag/functions.php:252) in /home/content/89/6909389/html/wp-content/plugins/wordpress-greetings/includes/dynamic-wp-greetbox.class.php on line 492”

    at the top of my blog. Even after I deleted the code and restored file to the way it was before, this message still appears. Anyway to get it off and asap???

  • Thanks these are some really nice code snippets and I have found them very useful. Thanks for sharing.

  • Hey,
    Some very useful code snippets you have provided here. Thanks a lot!

    All the best,

  • SJL

    Thanks for the snippets Jean-Baptiste! Custom post types has been one of my favourite new features built into WordPress 3.0. Although I have been struggling to get it to work probably with the custom fields template plugin.

  • shoaib khatri

    Nice and Informative Article.Please check my quality url…thankshow to get your ex back in a text message

  • I have struggled with the post for more than 2 days until I find out through a facebook page. I could say it have save my day and make it easy to customize my page named kem tri mun sakura. Thank god the answer is here