Home › Forums › Backend Issues (wp-admin) › Can't display a new field in menu items
Hi guys,
My name is Davide and I’m working on my new project, but I have a big iussue I can’t figure out how to fix it. I’m trying to put a second line of text in menu items on the main menu of wordpress. I added a new field in ACF Field Group and it works. I added the text in the backend of the menu and I added the code that I found in ACF documentation but… Nothing changed. Maybe there is some kind of error but I can’t figure out where it could be.
Can someone help me to find out how to solve this?
Thnaks guys,
Davide
PS: I post here some screen and my code in order to help you on understading what I’ve done until now
*** Screen of ACF Field Group ***
Click me
*** functions.php code ***
//Navbar from Bootstrap 4 to WordPress
require_once get_template_directory() . '/wp-bootstrap-navwalker.php';
//Add the subtitle field with Advanced Custom Fields
add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects', 10, 2);
function my_wp_nav_menu_objects( $items, $args ) {
foreach( $items as &$item ) {
$menu_navbar_sottotitolo = get_field('menu_navbar_sottotitolo', $item);
if( $icon ) {
$item->title .= '<br/><small>'.$menu_navbar_sottotitolo.'</small>';
}
}
return $items;
}
*** header.php code ***
<header class="site-header" role="banner">
<div id="mainNav" class="navbar navbar-expand-lg fixed-top unselectable">
<div class="container">
<a class="navbar-brand" href="index.html">
JustWeb Factory
</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
Menu
<i class="fa fa-bars"></i>
</button>
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'primary',
'depth' => 2,
'container' => 'div',
'container_class' => 'collapse navbar-collapse',
'container_id' => 'navbarContent',
'menu_class' => 'navbar-nav ml-auto',
'fallback_cb' => 'WP_Bootstrap_Navwalker::fallback',
'walker' => new WP_Bootstrap_Navwalker())
);
?>
</div>
</div>
</header>
*** Actual navbar ***
Click me
*** Desired navbar ***
Click me
change this:
$menu_navbar_sottotitolo = get_field('menu_navbar_sottotitolo', $item);
if( $icon ) {
$item->title .= '<br/><small>'.$menu_navbar_sottotitolo.'</small>';
}
to this:
$menu_navbar_sottotitolo = get_field('menu_navbar_sottotitolo', $item);
if( $menu_navbar_sottotitolo ) {
$item->title .= '<br/><small>'.$menu_navbar_sottotitolo.'</small>';
}
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.