PHP code question

Menubar PHP code question

  • Author
  • #12258 Reply
    Krissy Brady

    Hi there,

    I’ve run into a snag with my menu and have no clue how to fix it.

    I’m setting up a menu that looks something like this:

    Home > Conditions > Name of Condition

    My goal is to use PHP for the “Name of Condition” portion so that the name of the condition automatically changes depending on the page the visitor is on. So if someone’s on the Fibromyalgia page, the menu would show as:

    Home > Conditions > Fibromyalgia

    And if someone’s on the Long COVID page, it would automatically change to:

    Home > Conditions > Long COVID


    For the “Name of Condition” portion of the menu, I used PHP as the type, then under the PHP code I put:


    The page title does show up as part of the menu, but for some reason, it shows up three times:

    Home > Conditions > FibromyalgiaFibromyalgiaFibromyalgia

    I’ve been looking through troubleshooting options all afternoon and couldn’t be more stumped.

    I’ve tried wp_title(); and the_title(); and single_post_title(); etc. I’m not using an SEO plugin, so that can’t be the conflict. I turned off all plugins except the essentials and it didn’t solve the problem. I’m also struggling to find multiple/duplicate title tags within my theme files.

    Any guidance would be beyond appreciated! I’m in love with your plugin. 🙂


    #12259 Reply
    Plugin Author

    Hi Krissy,

    Try copying this code:

    return array (get_the_title(), '#');

    into the PHP code textarea of your menu item.

    Please let me know if this works for you!

    #12260 Reply
    Krissy Brady

    OMG IT WORKED! You’re my hero. Is there a way to make the array just show the title and not become a link, since technically they’re already on the page?

    Thanks for everything!

    #12261 Reply
    Plugin Author

    Unfortunately the PHP menu item can only produce a link, but you can try this:

    return array (get_the_title(), 'javascript:void(0)');

    so the link does nothing if clicked, while the previous code caused a jump to the top of the page.

    #12262 Reply
    Krissy Brady

    Amazing! This is perfect. Thanks so much for your help. 🙂

    #12263 Reply
    Plugin Author

    You are welcome!

Reply to: PHP code question
My Information