You can add that code as it is. If it do not work then you will need to change widget location. You can contact your theme what are the widget location they support. change primary to any one of them.
Thanks, I now realize that the reason why it might not work, is because I use a nav menu widget from Elementor in the header, not the theme menu.
Is it possible to add a widget location which is not defined by the theme, but Elementor?
I have changed the location to ‘header’ where the nav menu widget is, but no luck.
Normally theme follow https://codex.ww.wp.xz.cn/Widgetizing_Themes to add widget location. If Elementor follow same procedure then that will work, otherwise you will have to follow another method or code yourself.
Hi there
Show unread message count in menu
Adding this code as it is in functions.php, generates an HTTP ERROR 500?
add_filter( 'wp_nav_menu_items', 'fep_cus_add_menu_link', 10, 2 );
function fep_cus_add_menu_link( $items, $args ) {
if ( $args->theme_location == 'primary' ) {
$items .= '<li><a href="'. fep_query_url( 'messagebox' ) .'">' . sprintf(__('Message Box%s', 'front-end-pm'), fep_get_new_message_button() ) . '</a></li>';
}
return $items;
}
Regards
Carsten