Assign Menus to Theme Locations with theme activation

Well, I wrote a solution so writing it here: /* This action copies old theme’s theme location saves to new theme if new theme doesnt have saves before. */ add_action( ‘after_switch_theme’, ‘ajx_theme_locations_rescue’ ); function ajx_theme_locations_rescue() { // bug report / support: http://www.unsalkorkmaz.com/ // We got old theme’s slug name $old_theme = get_option( ‘theme_switched’ ); // … Read more

Dynamically link to the latest post or simulate request of specific post in page template

You can filter wp_nav_menu_objects and add a new item. Here is a simple plugin doing that: <?php # -*- coding: utf-8 -*- /** * Plugin Name: Latest Post In Menu * Description: Append a link to the latest post to all nav menus called with the argument <code>’add_latest_post’ => TRUE</code>. * Plugin URI: http://wordpress.stackexchange.com/q/59892/73 * … Read more

Add Commas Between Menu Items?

Use a very simple custom walker … class WPSE_82726_Comma_Walker extends Walker { public function walk( $elements, $max_depth ) { $list = array (); foreach ( $elements as $item ) $list[] = “<a href=”https://wordpress.stackexchange.com/questions/82726/$item->url”>$item->title</a>”; return join( ‘, ‘, $list ); } } … and call your menu like this: wp_nav_menu( array ( ‘theme_location’ => ‘your_registered_theme_location’, ‘walker’ … Read more

How to use a WordPress’ existing admin icon?

add_menu_page(); as far as I can tell does not work with screen_icon or the default CSS parameters. The $icon paramater only takes 2 options, an url or div (well 3 if you leave it empty), so that leaves you with these options: Hard-code the link to the icons which are located in wp-includes/images/wpicons.png. This is … Read more

wp_get_nav_menu_items how to exclude sub level menu items?

Think I worked it out!! I did a print_r on each $menu_item and saw there’s an array key called menu_item_parent in there. So I changed this: foreach ( (array) $menu_items as $key => $menu_item ) { $title = $menu_item->title; $url = $menu_item->url; $menu_output .= ‘<option value=”‘ . $url . ‘”>’ . $prefix . $title . … Read more

How do I create predefined menus for my theme?

Example code taken from new2wp.com located HERE // Function for registering wp_nav_menu() in 3 locations add_action( ‘init’, ‘register_navmenus’ ); function register_navmenus() { register_nav_menus( array( ‘Top’ => __( ‘Top Navigation’ ), ‘Header’ => __( ‘Header Navigation’ ), ‘Footer’ => __( ‘Footer Navigation’ ), ) ); // Check if Top menu exists and make it if not … Read more

non-clickable placeholder in the menu

Yes, this is possible by adding a custom link to the menu assigning it any url (for this example I just added #) then click add to menu. Once it’s on the menu open it and remove the url you assigned and save. If you don’t put the url initially WordPress won’t let you add … Read more

wp_nav_menu always falls back to a menu

wp_nav_menu() indeed tries a lot to provide you with a menu, and fallback_cb is only executed when nothing else works. From the code: If menu is provided and refers to an existing menu (looked up via wp_get_nav_menu_object(), which accepts an id, slug or name), this will be the menu Otherwise, if theme_location is set to … Read more