WordPress 3 Custom Menu Support in Thematic

More thematic child theme functions goodness :)

Having read the comments on this page: http://themeshaper.com/wordpress-menu-tricks/ I couldn't find a definitive copy and paste guide - looks like the HTML and PHP tags were being stripped out. So, leaning heavily on Tony L's work (thanks Tony!), here is a copy-paste-edit example. Simply add this to your Thematic child theme's functions.php file and you should find that you can then use the 'Menus' tab under WP's Appearance menu in the CMS.


// Add support for WP3 custom menus
add_theme_support( 'nav-menus' );

// Remove Thematic default menu
function remove_thematic_menu() {
remove_action('thematic_header','thematic_access',9);
}
add_action('init','remove_thematic_menu');

// Register the custom menu with the theme
function register_custom_menu() {
register_nav_menu( 'primary-menu', __( 'Primary Menu' ) );
}
add_action( 'init', 'register_custom_menu' );

// Output the new menu to the thematic header
function childtheme_access(){
wp_nav_menu( array('primary-menu', 'menu_class' => 'sf-menu' ) );
}
add_action('thematic_header', 'childtheme_access', 4);

Any mistakes, omissions or bugs are my own and I'd love to hear your feedback in the comments. Thanks for reading :)

Update

George Irwin kindly sent me an improvement on the 'Output the new theme to the thematic header' function, as follows:


// Output the new 3.0 menu to the thematic header
function childtheme_access(){?>
<div id="access">
<div class="skip-link"><a href="#content" title="<?php _e('Skip navigation to the content', 'thematic'); ?>"><?php _e('Skip to content', 'thematic'); ?></a></div>
<?php wp_nav_menu( array('primary-menu', 'menu_class' => 'sf-menu' ) ); ?>
</div><!-- #access -->
<?php
}
add_action('thematic_header','childtheme_access',4);

As George rightly points out, this keeps the new custom menu in line with the original as defined by Ian Stewart in the Thematic header-extensions.php file so that you don't need to change your CSS. Much better George, thanks :)

Update 2

Thanks to skarab and Manxstef, there's a further improvement to this code :)


// Output the new 3.0 menu to the thematic header
function childtheme_access(){?>
<div id="access">
<div class="skip-link"><a href="#content" title="<?php _e('Skip navigation to the content', 'thematic'); ?>"><?php _e('Skip to content', 'thematic'); ?></a></div>
<?php wp_nav_menu( array('primary-menu', 'container_class' => 'menu', 'menu_class' => 'sf-menu') ); ?>
</div><!-- #access -->
<?php
}
add_action('thematic_header','childtheme_access',9);

These tweaks ensure that the custom menu is created on the page in exactly the same place and with the same DOM as the default Thematic menus. Thanks both!


Digg This
Reddit This
Stumble Now!
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Buzz this!


Printed from: http://www.divydovy.com/2010/07/wordpress-3-custom-menu-support-in-thematic/. © divydovy 2014

21 Comments   »

RSS feed for comments on this post , TrackBack URI

Leave a Reply