Support » Plugins » Hacks » remove title="whatever" from wp_nav_menu

  • Resolved inspirationally



    I try removing the title from the top menu, but it doesn’t work. i mean the

    <a href="">title="news"news</a>.

    I need it, because I want to use a qTip on all links, but in the top navi it looks horrible when there’s also the submenu appearing.

    I tried the following code in my functions.php

    //removes title from top menu
    function my_nav_notitle( $menu ){
      return preg_replace('title=\"(.*?)\"','', '', $menu );
    add_filter( 'wp_nav_menu', 'my_nav_notitle' );

    and also altered the title=\”… line a bit, but could not find anything that works.

    Can you help, please?

    Thank you!!

Viewing 5 replies - 1 through 5 (of 5 total)

    Your args are out of place and your first arg is missing delimeters..

    preg_replace('| title=\"(.*?)\"|', '', $menu );

    See if that helps… 😉



    Hey Mark,

    thanks for your answer, sadly it doesn’t do the trick, even after cache purging.
    And even with wrapping the wp_nav_menu function into the my_nav_notitle.
    It simply doesn’t work.

    Just for testing, I also tried this
    solution to remove the <div>

      before the navigation, but it also doesn’t work.

      This is how I include the navi into the header.php with one of the functions for the case the add_filter part doesn’t work:

      <?php my_nav_unlister(wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'depth' => '2' )) ); ?>

      with the linked function.

      and even if i write

      <?php preg_replace( array( '#^<ul[^>]*>#', '#</ul>
      $#' ), '', (wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'depth' => '2' )) )); ?>


      <?php preg_replace('| title=\"(.*?)\"|', '', (wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'depth' => '2' )) )); ?>

      it doesn’t want to change.

      Is it possible, the mistake is (also) elsewhere?

    This works just fine for me..

    function my_nav_notitle( $menu ){
      return $menu = preg_replace('|title=\"(.+)\"|', '', $menu );
    add_filter( 'wp_nav_menu', 'my_nav_notitle' );

    Just make sure you’ve assigned a menu to your registred nav menu location, else it’ll render a page menu(the fallback) in place, which won’t adhere to the filter(since it’s a different kind of menu)..



    Thanks again, Mark. I did not know wp_nav_menu would become wp_page_menu automatically. So after changing my code to wp_page_menu and

    function my_nav_notitle( $menu ){
      return $menu = preg_replace('/ title=\"(.*?)\"/', '', $menu );
    add_filter( 'wp_page_menu', 'my_nav_notitle' );

    it did work at the end.

    Happy i could help… 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘remove title="whatever" from wp_nav_menu’ is closed to new replies.