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

Add a .last class to the last in each ul.sub-menu

Put the following in your functions.php class SH_Last_Walker extends Walker_Nav_Menu{ function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) { $id_field = $this->db_fields[‘id’]; //If the current element has children, add class ‘sub-menu’ if( isset($children_elements[$element->$id_field]) ) { $classes = empty( $element->classes ) ? array() : (array) $element->classes; $classes[] = ‘has-sub-menu’; $element->classes =$classes; } // We don’t … Read more

add span class inside wp_nav_menu link anchor tag

Have you tried using the before or link_before parameters in your array arguments when declaring your wp_nav_menu function? Note: use after or link_after for the opposite effect. Example, wp_nav_menu( //normal arguments here….etc ‘before’ => ‘<span class=”arrow”></span>’, //or ‘link_before’ => ‘<span class=”arrow”></span>’, ); From the Codex: $before (string) (optional) Output text before the of the link … Read more

Pulling Featured Images in to a WordPress Menu

You can do that by filtering the menu objects using wp_nav_menu_objects filter. The following example will replace all titles of the menu items pointing to posts or pages with an <img> tag of the post or page thumbnail if available. It will target a menu with a name of Posts Menu called in theme using … Read more

How to add ul class on nav

It’s simple just you need to add items_wrap parameter and add or edit class attr: wp_nav_menu( array( ‘theme_location’ => ‘top-menu’, ‘container’ => false, ‘items_wrap’ => ‘<ul class=”nav your_custom_class”>%3$s</ul>’, ));

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)