Link that refers to a menu item with dynamically generated URL

You can use the wp_get_recent_posts function in your own custom function. Something like this should work: function get_recent_post_link(){ // Restrict to latest post $args = array( ‘numberposts’ => ‘1’ ); // Get the post $latest_post = wp_get_recent_posts( $args ); foreach( $latest_post as $the_post ){ return get_permalink($the_post[“ID”]); } } You can the call the function in … Read more

Input type search in Menu

This is fine, but you if you want things to look “cleaner” and be easier to modify you could instead create a new file menu-search.php and add your HTML there then tweak your function a bit (don’t forget to prefix your functions) function myprefix_add_search_box_to_menu($items, $args) { if ( $args->theme_location == ‘menu-1’ ) { ob_start(); get_template_part( … Read more

Why does the ‘wp_nav_menu’ function work only until a menu is created?

This is due to the wp_nav_menu parameter fallback_cb: If the menu doesn’t exist, a callback function will fire. Default is ‘wp_page_menu’. Set to false for no fallback. You have not specified an alternative, so it uses the default, wp_page_menu. You could create your own function to display a page menu with the proper markup, or … Read more

Menu — How to add “current-menu-grand-ancestor” css class

Something like this will help you filter a menu item and add a custom class conditionally. ( Untested ) function add_nav_class( $classes ) { if ( class_exists( ‘current-menu-ancestor’ ) || $item->title == ‘blog’ ) { $classes[] = ‘current-menu-grand-ancestor’; } return $classes; } add_filter( ‘nav_menu_css_class’, ‘add_nav_class’, 10, 2 );

custom post type not showing in menu

// portfolio code function codenovo_portfolio_init(){ $labels = array( ‘name’ => _x(‘Portfolio’, ‘post type general name’), ‘singular_name’ => _x(‘Portfolio’, ‘post type singular name’), ‘add_new’ => _x(‘Add New’, ‘portfolio’), ‘add_new_item’ => __(‘Add New Portfolio’), ‘edit_item’ => __(‘Edit Portfolio’), ‘new_item’ => __(‘New Portfolio’), ‘view_item’ => __(‘View Portfolio’), ‘search_items’ => __(‘Search Portfolio’), ‘not_found’ => __(‘No portfolio found’), ‘not_found_in_trash’ => … Read more

How do I check menu slug in WordPress?

There is no official way as far as I know. You should be prefixing your menu_slug’s with some string that is almost guaranteed to be unique (e.g., ‘your_company_name_your_plugin_name_your_menu_slug’). That said, looking into the source for add_submenu_page(), the following should work, but I offer no guarantees (and, see the BIG caveat below): /** * test whether … Read more

Nav menu category links not showing

A wp_nav_menu is a manually created menu – WordPress doesn’t create it for you. If you want to keep using this function, you can go to either Appearance > Menus or Appearance > Customize > Menus, add links to the menu, and check the “primary” theme location under Display Location. However – if you’re just … Read more

Multiple WordPress Menus that will only display all pages

The keys for the array passed to register_nav_menus() should correspond with the ‘theme_location’ arguments in your calls to wp_nav_menu(). Since they do not, WordPress is unable to locate the appropriate menu and displays a default consisting of all top-level pages instead. Either change your ‘theme_location’ arguments to ‘menu-1’ and ‘menu-2’ or change the array keys … Read more

Looking for the best solution to build this Blog structure? Picture attached?

There are various ways to achieve what you are talking about within WordPress. 1) Multisite/Network. For each City (or whatever your top level is), you create a new site with a default theme. This allows for either www.website.com/paris/music or paris.website.com/music, depending on your requirements. Introductory info on Network sites Creating a WordPress Network 2) Write … Read more