So what you need to do is repeat what you’re doing, and we’ll use a foreach
loop to achieve it
I’ll give you an example of code that basically does what you need, but it creates an array of arrays. You initially created array
called $args
which represented a single link, but you need to create an array these $args
.
Once you create the array of $args
, you can run over the array
using a foreach
and add the nodes to the menu.
function add_link_to_admin_bar( $admin_bar ) {
$links = [
[
'parent' => 'site-name',
'id' => 'Lignano_Sabbiadoro',
'title' => 'Lignano Sabbiadoro',
'href' => '/case-vacanza/lignano-sabbiadoro-appartamenti-vacanze/',
'meta' => [
'target' => '_self',
]
],
[
'parent' => 'site-name',
'id' => 'My_Second_Link_2',
'title' => 'My Second Link',
'href' => '/case-vacanza/link-2/',
'meta' => [
'target' => '_self',
]
],
[
'parent' => 'site-name',
'id' => 'My_Third_Link_3',
'title' => 'My Third Link',
'href' => '/case-vacanza/link-3/',
'meta' => [
'target' => '_self',
]
],
];
foreach ( $links as $link ) {
$admin_bar->add_node( $link );
}
}
add_action( 'admin_bar_menu', 'add_link_to_admin_bar', 999 );