Comment supprimer UL sur wp_nav_menu?
-
-
Pourquoi voulez-vous quandmême supprimer l'UL lorsque vous l'ajoutez ànouveau?Vouspouvez utiliser lesparamètres `menu_class`et`menu_id`pour définir une classeet/ou un attributid sur l'UL.Why do you want to remove the UL when you add it again anyway? You can use the `menu_class` and `menu_id` parameters to set a class and/or id attribute on the UL.
-
Je veux utiliser Superfish.`menu_class`et`menu_id`ne fonctionneront que si lemenuest activé.Si lemenun'existepas,«menu_class»et «menu_id»n'estpas comme «
- »mais comme «
- 0
- 2011-01-28
- haha
».c'estpourquoitrop de questions sur `wp_nav_menu ()` vouspouvez letester :)I want use superfish. `menu_class` and `menu_id` only will working if menu is activated. If the menu doesn't exists `menu_class` and `menu_id` is not as `- ` but as `
`. thats why too much question about `wp_nav_menu()` you may test it :)6 réponses
- votes
-
- 2011-01-28
Lafonction wp_nav_menuprend un argument defallback_cb quiest lenom de lafonction àexécuter si lemenun'existepas. alors changez votre codeen quelque chose comme ceci:
function wp_nav_menu_no_ul() { $options = array( 'echo' => false, 'container' => false, 'theme_location' => 'primary', 'fallback_cb'=> 'fall_back_menu' ); $menu = wp_nav_menu($options); echo preg_replace(array( '#^<ul[^>]*>#', '#</ul>$#' ), '', $menu); } function fall_back_menu(){ return; }
vouspouvezmême supprimer le conteneur dumenuet faire d'autres choses avec quelques arguments supplémentairesenvoyés à la fonction wp_nav_menu
J'espère que cela vous aidera.
The function wp_nav_menu takes an argument of fallback_cb which is the name of the function to run if the menu doesn't exist. so change you code to something like this:
function wp_nav_menu_no_ul() { $options = array( 'echo' => false, 'container' => false, 'theme_location' => 'primary', 'fallback_cb'=> 'fall_back_menu' ); $menu = wp_nav_menu($options); echo preg_replace(array( '#^<ul[^>]*>#', '#</ul>$#' ), '', $menu); } function fall_back_menu(){ return; }
you can even remove the container from the menu and do other stuff with some more arguments sent to the wp_nav_menu function
Hope this helps.
-
@ בניית אתרים - Mercipour votreexplication.Maisje deviensflouici.Selon lanote sur `nav-menu-template.php``fallback_cb - Si lemenun'existepas,unefonction de rappel se déclenchera.La valeurpar défautest «wp_page_menu».Définir àfalsepourpas de repli` Que dois-je remplacerpour que `wp_nav_menu_no_ul ()`fonctionne sije définisfalse sur `fallback_cb`?Parce qu'il retourne videpour lemoment.@בניית אתרים - Thanks for your explanation. But I'm getting blur here. According to the note on `nav-menu-template.php` `fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'. Set to false for no fallback` What should I replace to make `wp_nav_menu_no_ul()` working if I set false to the `fallback_cb` ? Because it return blank for now.
- 0
- 2011-01-28
- haha
-
Maintenant compris :) Mercibeaucoup בניית אתרים.BTW,commentprononcer votre surnom?Mine `ha ha`Now understood :) Thanks a lot בניית אתרים. BTW, how do I pronounce your nickname? Mine `ha ha`
- 0
- 2011-01-28
- haha
-
LOL,content que vous y alliez.LOL, glad you go it.
- 0
- 2011-01-28
- Bainternet
-
Jeme suis demandé lamême chose,c'est l'hébreuje suppose,ce qui serait unetraductionexacte,par curiosité .. :)I've wondered the same thing, it's Hebrew i assume, what would be an accurate translation, out of curiousity.. :)
- 0
- 2011-01-28
- t31os
-
:) oui c'est l'hébreuet c'est unpseudo quej'ai ramassé un certaintemps qui,s'ilest correctementtraduit,signifie quelque chose comme "conception de sites Web".:) yes it Hebrew and its a nick i picked up a while a go that if properly translated means something like "web design".
- 0
- 2011-01-28
- Bainternet
-
Veuillez voir l'autre réponse de Martti à ce sujet.Au lieu d'ajouter le `
- `puis d'exécuter une rechercheet de remplacerpour le supprimer ànouveau,vous devez simplementne pas l'ajouteren premier lieu.Faites-leen utilisant l'option `items_wrap`
Please see the other answer from Martti about this. Instead of adding the `- ` and then running a find & replace to remove it again, you should simply just not add it in the first place. Do so using `items_wrap` option
- 0
- 2015-03-20
- mikemike
-
- 2011-12-07
Enfait,WordPressprenden charge celapar défaut:
wp_nav_menu(array( 'items_wrap' => '%3$s' ));
La valeurpar défautpour
items_wrap
est<ul id=\"%1$s\" class=\"%2$s\">%3$s</ul>
.Actually, WordPress supports this by default:
wp_nav_menu(array( 'items_wrap' => '%3$s' ));
The default for
items_wrap
is<ul id=\"%1$s\" class=\"%2$s\">%3$s</ul>
.-
C'est labonne réponse.Les autres réponses defaire unfind & replaceprogrammatiquepour supprimer `
- ` après qu'il a déjà été ajouté sontjuste à l'envers
This is the correct answer. The other answers of doing a programmatic find & replace to remove `- ` after it has already been added are just backwards
- 3
- 2015-03-20
- mikemike
-
`'container'=>false` si vous souhaitez également vous débarrasser du wrapping``.`'container' => false` if you want to get rid of the wrapping `` as well.
- 0
- 2017-08-10
- George Dimitriadis
C'est vrai configurable dans WordPresspar défaut.Merci!It is true configurable in WordPress by default. Thanks!- 0
- 2018-04-02
- Abdalla Arbab
meilleure réponse,pasbesoin de hackbest answer, no need for hack- 0
- 2019-02-02
- Eman
celane fonctionnepaspourmoi dans wp 5.2this is not working for me in wp 5.2- 0
- 2019-06-30
- rafaelphp
- 2014-05-14
Le code ci-dessous devrait lefaire simplement.
<?php $my_menu = array( 'menu' => 'main-menu', 'container' => '', 'items_wrap' => '%3$s' ); wp_nav_menu( $my_menu ); ?>
Référencez ce lienpour lafonction wp_nav_menu http://codex.wordpress.org/Function_Reference/wp_nav_menu
The below code should simple do it.
<?php $my_menu = array( 'menu' => 'main-menu', 'container' => '', 'items_wrap' => '%3$s' ); wp_nav_menu( $my_menu ); ?>
Reference this link for the wp_nav_menu function http://codex.wordpress.org/Function_Reference/wp_nav_menu
- 2015-11-17
Si vous souhaitezimprimer uniquement lesbalises
<a>
,vouspouvezprocéder comme suit:$primaryMenu = array( 'theme_location' => 'primary', 'menu' => '', 'container' => '', 'container_class' => false, 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => 'primary-menu', 'echo' => false, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'depth' => 0, 'walker' => '' ); echo strip_tags( wp_nav_menu( $primaryMenu ), '<a>' );
If you want to print only
<a>
tags, you may go this way:$primaryMenu = array( 'theme_location' => 'primary', 'menu' => '', 'container' => '', 'container_class' => false, 'container_id' => '', 'menu_class' => 'menu', 'menu_id' => 'primary-menu', 'echo' => false, 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'depth' => 0, 'walker' => '' ); echo strip_tags( wp_nav_menu( $primaryMenu ), '<a>' );
-
cetravailparfaitpourmoi,définir uniquement `` 'items_wrap'=> '% 3 $ s' 'n'apas d'effet dans wp 5.2this work perfect for me, setting only ` 'items_wrap' => '%3$s' ` does not has effect in wp 5.2
- 0
- 2019-06-30
- rafaelphp
- 2014-04-05
Pourmoi,ce qui afonctionné était ceci:
<?php wp_nav_menu( array( 'container' => '', 'items_wrap' => '%3$s' ) ); ?>
J'espère que cela aide.
For me what worked was this:
<?php wp_nav_menu( array( 'container' => '', 'items_wrap' => '%3$s' ) ); ?>
Hope it helps.
- 2019-12-28
Je sais que cette réponsen'estpastout àfaitpour cette question,maisil y atellement degens qui savent comment supprimer lesbalises ulet li dans WordPresset ajouter une autrebalise dans WordPress.
Comme avant d'appliquermon code WordPress donne cestypes de sortie dans lemenu
<ul class="*****"><li>abc</li></ul>
Mais quelqu'un veut changer ulen divet lien balise,alors vous devriez utiliser le code ci-dessous
<?php $menuParameters = array( 'menu' => 'primary_menu', 'link_before' => '<span>', 'link_after' => '</span>', 'before' => '<div class="tp-primary-header mui-top-home">', 'after' => '</div>', 'container' => false, 'echo' => false, 'depth' => 0, ); echo strip_tags(wp_nav_menu( $menuParameters ), '<a><span><div>' ); ?>
Cela donne la sortie dans leformat suivant
<div class="tp-primary-header mui-top-home"><a href="#"><span>ABC</span></a></div> <div class="tp-primary-header mui-top-home"><a href="#"><span>def</span></a></div> <div class="tp-primary-header mui-top-home"><a href="#"><span>XYZ</span></a></div>
I know that this answer is not completely for this question but there are so many people who come to know how to remove ul and li tag in WordPress and add another tag in WordPress.
Like before applying my code WordPress gives these types of output in menu
<ul class="*****"><li>abc</li></ul>
But someone wants to change ul into div and li into a tag then you should use below code
<?php $menuParameters = array( 'menu' => 'primary_menu', 'link_before' => '<span>', 'link_after' => '</span>', 'before' => '<div class="tp-primary-header mui-top-home">', 'after' => '</div>', 'container' => false, 'echo' => false, 'depth' => 0, ); echo strip_tags(wp_nav_menu( $menuParameters ), '<a><span><div>' ); ?>
This gives output in the following format
<div class="tp-primary-header mui-top-home"><a href="#"><span>ABC</span></a></div> <div class="tp-primary-header mui-top-home"><a href="#"><span>def</span></a></div> <div class="tp-primary-header mui-top-home"><a href="#"><span>XYZ</span></a></div>
-
J'ai recherché sur ce siteet j'aitrouvé denombreuses réponses à cette question. Laplupart d'entreeuxne travaillentpas surmonthème.
Voici une solution unique: trouvé et ilfonctionne selonmesbesoins.
Ce code supprimera
ul
au débutet à lafin dewp_nav_menu()
. Donc,dansmonthème,je viens d'écrireMais leproblème se reproduit lorsqueje n'ajouteni n'active aucunmenu via admin.
http://domain.com/wp-admin/nav-menus.php
Question:
Commentpuis-je supprimer le
<div><ul>**</ul></div>
que lemenu soit actif ounon. Faites lemoi savoirEnfinje l'aifaitfonctionner :)
functions.php
header.php