20

Adding Backwards Compatible WordPress Menus To Your Theme

Before you dive in and start going all crazy with WordPress 3.0 you should consider making things work universally, as a best practice rule. A quick tip for updating your theme or for how you create new ones in the future. Here's how you can easily make adding menus backwards compatible....
Adding Backwards Compatible WordPress Menus To Your Theme

So You Want To Make A Menu?

With the cool new WordPress 3.0 coming out sometime in the future, you may be interested in updating the way you make you're menus in your themes. Then you think, but what about people that haven't yet updated to WordPress 3.0, the menu won't show. There's an easy way to make a fallback to show the menu the old fashioned way.

Here's what you have to do

	<?php if (function_exists( 'wp_nav_menu' )) {	
		wp_nav_menu( array('menu' => 'MENU NAME'  ));
	} else {
	?>

	<ul>
		<li class="page_item"><a href="<?php echo get_settings('home'); ?>/" title="Home">Home</a></li>					
		<?php wp_list_pages('sort_column=menu_order&depth=2&title_li='); ?>
	</ul>
<?php } ?>			

It's as simple as that. Just check for whether or not the wp_nav_menu function exists. If it does, then show that menu. If not, then show the wp_list_pages or wp_list_categories whichever one you may be using in your theme.

Let me know if you have any questions below.

Shortlink:

Get automatic updates! Subscribe to Our RSS Feed or Get Email Updates sent straight to your inbox!

About the Author

Jared is from Boston working as a web and graphic designer. Also owns the design blog Tweeaks.com, and has designed many other websites powered by Wordpress including the New2WP theme.

Level: Noob

User Comments

( ADD YOURS )

  1. Thanks for the tips, Jared. Hope to see more of you custom themes at WordPress. Thanks for sharing.


  2. I agree. Before going gaga over WP 3.0 make things work better. I know everybody is as excited as I am.

  1. Avatar

    Your Name
    May 23