Categories
Code Uncategorized WordPress

How to remove a nav menu location in WordPress 3.0.0

This function is in WordPress 3.0.1. You can now just call unregister_nav_menu and don’t need to put it in your child theme

One of the great additions to WordPress 3.0 is navigation menus.  One of the aspects that it contains is the ability for a theme to register a nav menu location and for the user to assign any menu they want to that location.  GREAT!  Except that a missing piece of functionality is the ability for Child Themes to remove a location that it might no longer want.  I’ve created a ticket and submitted a patch, but if you need that functionality now, just add the code below to you child theme’s functions.php file:
[php]
if (! function_exists(‘unregister_nav_menu’) ):
function unregister_nav_menu( $location ) {
global $_wp_registered_nav_menus;

if (is_array($_wp_registered_nav_menus) && array_key_exists( $location, $_wp_registered_nav_menus ) ){
unset( $_wp_registered_nav_menus[$location] );
return true;
}

return false;

}
endif;
[/php]

Then all you need to do is call:
[php]
//Remove Twenty Ten Default Menu Location
unregister_nav_menu(‘primary’);[/php]
At some point after the nav menu is registered. I like to use the init hook.

Categories
Uncategorized WordPress

WordPress 3.0 sneak peak presentation from the Portland WordPress User Group

Last night I presented at Portland WordPress user group on some of the features and changes coming in WordPress 3.0. In case you weren’t in attendance, my slides are below, and what I went over can be summed up in a couple of points:

  • The changes taking place are going to make things easier for you, but nothing is groundbreaking
  • It’s still Alpha at this point. Things can and will change before it’s released.
  • Multisite in a true sense is not going to work on a lot of shared hosting plans. You can still use Sub Directories though

After my presentation I gave a quick case study of what would happen if the A-team decided to use WordPress Multisite. I figured BA would be put in charge and would create the initial site theateam.tld. The next step for him would be to create a site for himself, ba.theateam.tld . And of course when the time came, he would create a site for a film they were using as cover, Boots and Bikinis. He would use the domain mapping plugin and thus would have just created three sites in a matter of minutes.

Continuing with my case study, I built a quick plugin to demonstrate just how easy it is to add a new post type. Figuring that the team would want to show off their missions, that’s what it does.

[php]
/*
Plugin Name: A-Team Missions
Description: I love it when a plan comes together
Author: Aaron Jorbin
Version: 1.0
Author URI: http://aaron.jorb.in/
*/

function post_type_missions() {
register_post_type( ‘missions’,
array( ‘label’ => __(‘missions’), ‘public’ => true, ‘show_ui’ => true ) );
register_taxonomy_for_object_type(‘post_tag’, ‘movies’);
}
add_action(‘init’, ‘post_type_missions’);

function loop_missions(){
$missions = get_posts(‘post_type=missions’);
ob_start();
echo "<ul>";
foreach ($missions as $mission){
echo "<li>".$mission->post_title."</li>";
}
echo "</ul>";
}

add_shortcode(‘missions’, ‘loop_missions’);

[/php]

It’s just that easy. Two functions. The first adds our post type, and the second adds a shortcode to display the title of each mission so it’s embeddable anywhere.

If you want to know more about my presentation, Kathleen Mcdade was live tweeting it.

I’m going to have some more posts in the coming weeks about WordPress 3.0. If you have any questions, please ask below.

View more presentations from aaronjorbin.