1. Home
  2. Knowledge Base
  3. Customizations
  4. PHP Functions
  5. How to Enable the Use of Shortcodes in Header Menu Items

How to Enable the Use of Shortcodes in Header Menu Items

Introduction

BuddyBoss does not allow shortcodes to be used in menu navigation labels. You can enable this functionality by adding a small custom function to your active theme. This will allow you to insert shortcodes directly into menu item labels, which WordPress will then render correctly on the front-end. This guide explains how you can enable the use of shortcodes in header menu items

Custom Workaround

Before proceeding, make sure you have a complete site backup.

  1. Go to Appearance > Theme Editor in your WordPress admin dashboard.
  2. Under Select theme to edit, choose your active theme (preferably a BuddyBoss Child Theme), then click Select.
  3. From the Theme Files list, open Theme Functions (functions.php).
  4. Add the following code just before the closing PHP tag (?>):
/**
 * Enable shortcodes for menu navigation.
 */
if ( ! has_filter( 'wp_nav_menu', 'do_shortcode' ) ) {
    add_filter( 'wp_nav_menu', 'shortcode_unautop' );
    add_filter( 'wp_nav_menu', 'do_shortcode', 11 );
}
  1. Click Update File to save the changes.
  2. Go to WordPress Admin > Appearance > Menus and add a shortcode to a menu item’s navigation label.
  3. Save the menu.

Note: Modifications are typically considered custom work, but we are making an exception in this case. Please review the BuddyBoss Support Policy.

Troubleshooting and FAQs

Q: The shortcode is still showing as plain text.
A: Make sure you added the code to your child theme’s functions.php file, not the parent theme. Also, clear any caching plugins and refresh the front-end.

Q: Will this affect other parts of the site?
A: No. This code only modifies menu item labels and allows shortcodes to be rendered there.

Q: Can I revert this change easily?
A: Yes. Remove or comment out the code from functions.php and save the file.

Was this article helpful?

Related Articles

Subscribe to Our Newsletter

Stay In Touch

Subscribe to our Newsletter, and we’ll send you the latest news from BuddyBoss

  • This field is hidden when viewing the form
  • This field is for validation purposes and should be left unchanged.

To speak to our Agency consultant, fill in the form found at our Contact Page.

  • Get Started

    Enter your name and email address to get started with your project...

  • This field is for validation purposes and should be left unchanged.