0

Before upgrading to Wordpress 4.8, I could do a string search and replace on the wp_nav_menu(). I had a few sites running 4.7.5 and code was working. Soon as upgrading code below did nothing.

    <?php
    $args = array(
         'theme_location'  => $nav_name,
         'container'  => 'nav',
         'items_wrap' => '<ul>%3$s</ul>',
         'container_class' => " ",
         'echo' => false
    );
    $nav = wp_nav_menu( $args );
    $nav = str_replace('<ul class="sub-menu">', '<div class="mobile-drop"><ul>', $nav);
    $match = '</ul>'."\n".'</li>';
    $nav = str_replace($match, '</ul></div></li>', $nav);
    echo $nav;
    ?>

Now post 4.8, it doesn't replace the "sub-menu" with my class called "mobile-drop". When I look at the html I do see an outputted "sub-menu" with double quotes.

1 Answer 1

0

I found that Wordpress added an extra space.

<ul  class="sub-menu"> 

so the search and replace could not be done correctly. If you look in the code inspector (developer tools) you won't see the extra space. Once going to view source code (command + shift + U), I noticed the actual output code had the extra space. Hope this will help someone with similar problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.