• Hi! I have a WordPress menu and I’m adding HTML to it, such as “Getting<br />Started”. This will put “Getting” and “Started” on their own lines. All works well, but every once in a while (for reasons I haven’t quite figured out), it will remove the HTML and turn in to “GettingStarted”. I don’t know what triggers it. Maybe updating my header.php file? Maybe uploading new posts? It’s annoying and temporarily breaks our site until I go in and fix it.

    Is there something I’m doing wrong? Is something interfering? Should I be escaping my HTML characters somehow, or using a different command like “\n”?
    Yes, I’ve disabled my other plugins and it still does this. Yes, my WordPress is the latest version.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Newlines (“\n”) are ignored by browser rendering engines, a break tag should be honored. Did you simply enter “Getting<br />Started” into the navigation label field of the usual menu UI? I have a site with the exact same sort of labels and have never encountered a problem.

    Unless you can reliably reproduce the behavior, it’s going to be difficult to track down the cause. I’ve a couple ideas for possible work arounds. See if simply removing the space within the break tag helps any. Add some CSS that targets only that one particular menu item. Set the container’s width and padding so that the browser is forced to line feed the label to stay within the container even if the break tag were not there.

    The CSS could become problematic should the menu be edited in certain ways, but it should solve the issue for the current menu.

    Thread Starter multimediocrity

    (@multimediocrity)

    The CSS is a good idea but impractical in this case. I tried it without the space also and it still removed it. I did try the \n too and realized that didn’t work.

    Yes, I added “Getting<br />Started” into the navigation label field of the usual menu UI. It works, but it doesn’t stay, and I’m a bit bothered, haha.

    OOOOH! IDEA! I said I disabled all my plugins but I couldn’t full-out test everything. Maybe Nested Pages is rewriting my headers?

    Moderator bcworkz

    (@bcworkz)

    Oh, you use that plugin to manage menus? That’s almost certainly the cause. You could try asking for suggestions in the plugin’s dedicated support forum. But looking at other support topics there, it doesn’t look very promising 🙁

    If you have some ability to code PHP, you could attempt to locate the offending code and disable it. Still, you would need to know what you do in the UI that causes the issue in order to have a starting point. There’s too much code to just blindly start searching for the cause.

    Or possibly easier, intercept the menu output stream and fix up the stream as needed. For example, if \n is reliably retained by the plugin, intercept the output and replace instances of \n with <br/>. If not \n then some other unlikely characters, || perhaps. Does this plugin’s menu still use the wp_nav_menu() call on templates to output the menu? If so, probably hooking the “pre_wp_nav_menu” filter with a late priority will allow interception of the menu output. I can’t be sure, but if wp_nav_menu() is still used, it’s very likely a solution.

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

The topic ‘Adding HTML to Menu’ is closed to new replies.