Add A Menu Item To A WP_Nav_Menu Navigation via PHP Function

You can use wp_update_nav_menu_item() to programmatically add a new menu item to the database. Since this change persists, you shouldn’t execute this functionality on every page – it’s best used as a one-off (though in that case it might be easier and more efficient to use WP CLI as suggested by WebElaine in the comments), …

Read more

Why don’t ‘wp_nav_menu’ CSS classes work 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

Is it possible to know which menus are owned by a plugin?

Technically speaking, you can use PHP’s debug_backtrace() function along with appropriate WordPress hooks like wp_nav_menu, add_menu_page etc. to get the file names and function names these WordPress API functions/hooks are called from. From there, you should be able to determine which plugin is creating or modifying what menu. However, please note that functions like debug_backtrace() …

Read more

Adding padding above menu

This forum is specific to WordPress internal workaround and your question is regarding element styling which does not belong here. Please try to use specific sites according to your question. For your problem, add the following lines in your theme’s stylesheet and it should be fixed. #masthead #cms-header.header-ontop { padding-top:15px; } #masthead #cms-header.header-sticky { padding-top:0; …

Read more

Custom div to to menu wordpress afte

As toscho mentioned this can be done with the items_wrap argument. It would be something like this: ‘items_wrap’ => ‘<ul id=”%1$s”>%3$s</ul><div id=”MYDIV”></div>’ For more info see here.

Theme supports only one menu. I need to add more – but how? [closed]

You need to add a new menu here: function register_nisarg_menus() { // This theme uses wp_nav_menu() in one location. register_nav_menus( array( ‘primary’ => esc_html__( ‘Top Primary Menu’, ‘nisarg’ ), ‘my_new_menu’ => esc_html__( ‘My New Menu’, ‘nisarg’ ) //this is the new line ) ); } and you use it like this in your HTML code …

Read more

How does WP knows which template to use for a page

The native logic of template choice is contained in file aptly named template-loader.php. It processes the current context and calls respective get_*_template() functions, until a match is found. This process results in what is called Template Hierarchy. However as it was pointed out this only covers native core logic. Plugins can wildly customize this process …

Read more

Two Homes In Navigation Menu

This sounds like the same problem I had, WordPress added a home option to the menu without it being added in the appearance menu items so I could not remove it. I googled for ages and found two solutions. Neither of them worked but if I combined the two they did. Open the functions.php file …

Read more