Walker_Nav_Menu: Items not nested correctly

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I want to add "anchor" tag adjacent to every "list item" that has children.



this is my Walker_Nav_Menu class:



class Menu_Walker extends Walker_Nav_Menu {

function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )

$ident = str_repeat( "t", $depth );

if ( $args->walker->has_children )

$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;

// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";

// added tag after
$output .= "<a class="added" href="#">txt</a>";

else

$classes = 'menu-item menu-item-' . $item->ID;

// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";




This is the structure of the menu in WordPress:



enter image description here



But the output is not nested correctly as you can see in image below:



enter image description here



Please help me fix this problem










share|improve this question









New contributor




Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
    – Krzysiek Dróżdż
    2 hours ago






  • 1




    @Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
    – Rozo
    2 hours ago

















up vote
2
down vote

favorite












I want to add "anchor" tag adjacent to every "list item" that has children.



this is my Walker_Nav_Menu class:



class Menu_Walker extends Walker_Nav_Menu {

function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )

$ident = str_repeat( "t", $depth );

if ( $args->walker->has_children )

$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;

// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";

// added tag after
$output .= "<a class="added" href="#">txt</a>";

else

$classes = 'menu-item menu-item-' . $item->ID;

// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";




This is the structure of the menu in WordPress:



enter image description here



But the output is not nested correctly as you can see in image below:



enter image description here



Please help me fix this problem










share|improve this question









New contributor




Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
    – Krzysiek Dróżdż
    2 hours ago






  • 1




    @Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
    – Rozo
    2 hours ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I want to add "anchor" tag adjacent to every "list item" that has children.



this is my Walker_Nav_Menu class:



class Menu_Walker extends Walker_Nav_Menu {

function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )

$ident = str_repeat( "t", $depth );

if ( $args->walker->has_children )

$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;

// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";

// added tag after
$output .= "<a class="added" href="#">txt</a>";

else

$classes = 'menu-item menu-item-' . $item->ID;

// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";




This is the structure of the menu in WordPress:



enter image description here



But the output is not nested correctly as you can see in image below:



enter image description here



Please help me fix this problem










share|improve this question









New contributor




Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I want to add "anchor" tag adjacent to every "list item" that has children.



this is my Walker_Nav_Menu class:



class Menu_Walker extends Walker_Nav_Menu {

function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 )

$ident = str_repeat( "t", $depth );

if ( $args->walker->has_children )

$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;

// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";

// added tag after
$output .= "<a class="added" href="#">txt</a>";

else

$classes = 'menu-item menu-item-' . $item->ID;

// actual link
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";




This is the structure of the menu in WordPress:



enter image description here



But the output is not nested correctly as you can see in image below:



enter image description here



Please help me fix this problem







menus






share|improve this question









New contributor




Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 1 hour ago









Krzysiek Dróżdż

11.7k42637




11.7k42637






New contributor




Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









Rozo

132




132




New contributor




Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Rozo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
    – Krzysiek Dróżdż
    2 hours ago






  • 1




    @Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
    – Rozo
    2 hours ago

















  • Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
    – Krzysiek Dróżdż
    2 hours ago






  • 1




    @Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
    – Rozo
    2 hours ago
















Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
– Krzysiek Dróżdż
2 hours ago




Of course they’re not nested correctly. You close li tag in your start_el, so how could they be correct ;)
– Krzysiek Dróżdż
2 hours ago




1




1




@Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
– Rozo
2 hours ago





@Krzysiek Dróżdż omg you're correct, I was trying to solve this problem for the last 2 hours, removing the li closing tag solved it thank you so much.
– Rozo
2 hours ago











1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










You have this problem, because of your code ;)



function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) 

$ident = str_repeat( "t", $depth );

if ( $args->walker->has_children )

$classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;

// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";

// added tag after
$output .= "<a class="added" href="#">txt</a>";

else

$classes = 'menu-item menu-item-' . $item->ID;

// actual link
// you SHOULDN'T close the li tag in here
$output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";




In your start_el you close the li tag, so children can't be printed inside of it...






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "110"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    Rozo is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f316299%2fwalker-nav-menu-items-not-nested-correctly%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    You have this problem, because of your code ;)



    function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) 

    $ident = str_repeat( "t", $depth );

    if ( $args->walker->has_children )

    $classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;

    // actual link
    // you SHOULDN'T close the li tag in here
    $output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";

    // added tag after
    $output .= "<a class="added" href="#">txt</a>";

    else

    $classes = 'menu-item menu-item-' . $item->ID;

    // actual link
    // you SHOULDN'T close the li tag in here
    $output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";




    In your start_el you close the li tag, so children can't be printed inside of it...






    share|improve this answer
























      up vote
      2
      down vote



      accepted










      You have this problem, because of your code ;)



      function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) 

      $ident = str_repeat( "t", $depth );

      if ( $args->walker->has_children )

      $classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;

      // actual link
      // you SHOULDN'T close the li tag in here
      $output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";

      // added tag after
      $output .= "<a class="added" href="#">txt</a>";

      else

      $classes = 'menu-item menu-item-' . $item->ID;

      // actual link
      // you SHOULDN'T close the li tag in here
      $output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";




      In your start_el you close the li tag, so children can't be printed inside of it...






      share|improve this answer






















        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        You have this problem, because of your code ;)



        function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) 

        $ident = str_repeat( "t", $depth );

        if ( $args->walker->has_children )

        $classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;

        // actual link
        // you SHOULDN'T close the li tag in here
        $output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";

        // added tag after
        $output .= "<a class="added" href="#">txt</a>";

        else

        $classes = 'menu-item menu-item-' . $item->ID;

        // actual link
        // you SHOULDN'T close the li tag in here
        $output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";




        In your start_el you close the li tag, so children can't be printed inside of it...






        share|improve this answer












        You have this problem, because of your code ;)



        function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) 

        $ident = str_repeat( "t", $depth );

        if ( $args->walker->has_children )

        $classes = 'menu-item-has-children menu-item menu-item-' . $item->ID;

        // actual link
        // you SHOULDN'T close the li tag in here
        $output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";

        // added tag after
        $output .= "<a class="added" href="#">txt</a>";

        else

        $classes = 'menu-item menu-item-' . $item->ID;

        // actual link
        // you SHOULDN'T close the li tag in here
        $output .= "$ident<li class="$classes"><a href="$item->url">$item->title</a></li>n";




        In your start_el you close the li tag, so children can't be printed inside of it...







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        Krzysiek Dróżdż

        11.7k42637




        11.7k42637




















            Rozo is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            Rozo is a new contributor. Be nice, and check out our Code of Conduct.












            Rozo is a new contributor. Be nice, and check out our Code of Conduct.











            Rozo is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f316299%2fwalker-nav-menu-items-not-nested-correctly%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery