Shortcode in megamenu
-
Subject: fl_builder_insert_layout shortcode not rendering in Max Mega Menu widget content (shortcode works elsewhere) — workaround & request
Hi Max Mega Menu team,
After updating Max Mega Menu (core 3.7) and Max Mega Menu Pro (2.4.4) I hit an issue where a Beaver Builder shortcode placed inside a menu widget (or a menu item widget content) stopped rendering. The shortcode works fine elsewhere (posts/templates), but inside Mega Menu widget content it was output literally (e.g.
[fl_builder_insert_layout slug="investor-survey-nav-cta-template"]) instead of being processed.This looked like Mega Menu is outputting widget/menu content without running WordPress content filters (so shortcodes are not parsed). I tested locally and found a safe workaround — but I think the plugin should either run
the_contentor otherwise ensure shortcode processing for widget/menu content, or clearly document the behavior.Environment
- Max Mega Menu: core 3.7 (local environment)
- Max Mega Menu Pro: 2.4.x (my copy shows 2.4.4)
- Beaver Builder: shortcodes registered as
fl_builder_insert_layout - VIP Go hosting (important: client mu-plugins location matters)
Reproduction steps
- Add a widget/menu item to a Max Mega Menu panel and paste:
[fl_builder_insert_layout slug="beaver-builder-template"] - Visit the front-end as an unauthenticated user (or a non-builder session).
- Observe the literal shortcode printed instead of the rendered layout.
What I verified
fl_builder_insert_layoutis registered by the Beaver Builder plugin (FLBuilderShortcodes::init()).- The shortcode renders fine when used in a post template (
do_shortcode('[fl_builder_insert_layout slug="beaver-builder-template"]')). - Mega Menu outputs the menu item/widget content without the normal
the_contentfilter path, so shortcodes aren’t processed.
Workaround I implemented (VIP-friendly)
- On VIP Go the correct place for client mu-plugins is
wp-content/client-mu-plugins/(per VIP docs). I added a small client-mu-plugin that appliesthe_contentonly when the widget/menu content contains the Beaver Builder layout shortcode. This keeps the change scoped and safe.
Copy-paste client mu-plugin (recommended for VIP Go)
- File: mm-shortcode-filter.php
<?php
/**
* Client MU-plugin: Mega Menu Shortcode Content Filter
* Ensures Max Mega Menu widget/menu item content runs through the_content() when it contains Beaver Builder layouts.
* Deploy this file via VIP'sclient-mu-pluginsdirectory so it loads in VIP Go safely.
*
* Only processes content that contains[fl_builder_insert_layoutto limit scope.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
add_filter( 'megamenu_walker_nav_menu_start_el', function( $item_output, $item, $depth, $args ) {
if ( ! is_object( $item ) ) {
return $item_output;
}
if ( property_exists( $item, 'type' ) && $item->type === 'widget' && ! empty( $item->content ) ) {
if ( false !== strpos( $item->content, '[fl_builder_insert_layout' ) ) {
$processed = apply_filters( 'the_content', $item->content );
if ( ! empty( $processed ) ) {
return $processed;
}
}
}
return $item_output;
}, 10, 4 );Alternative (plugin-side) suggestion
- The same effect could be provided inside the plugin by running
apply_filters('the_content', $item->content)in the walker when rendering widget menu items. Example quick snippet for walker.class.php:
<?php
// inside start_el() when handling widget-type items
if ( $item->type == 'widget' ) {
if ( $item->content ) {
// Apply the_content so shortcodes and embeds are processed
$item_output = apply_filters( 'the_content', $item->content );
} else {
$item_output = "<!-- widget is empty -->";
}
}Why I scoped the filter to only the Beaver Builder shortcode
- Minimizes risk of changing other menu behaviors
- Avoids parsing content that legitimately should be output raw (if that’s expected by some users)
- Keeps change safe while we figure out an upstream fix
Questions / request for plugin team
- Is Mega Menu intentionally skipping
the_contentwhen outputting widget/menu content? If so, can we add an option to enable content-filtering for widgets/panels? - If the plugin supports cached HTML output for menus, could you ensure cached generation also runs
the_contentso shortcodes are preserved in cached versions? - Is there a recommended hook or filter you prefer for dealing with 3rd-party builder shortcodes so we don’t need client-side workarounds?
Thanks! I’d appreciate advice on whether this should be treated as a bug (shortcodes not processed) or an intentional behavior and, if the former, whether you’d accept a patch that ensures
the_contentis applied to widget content (or a more configurable approach).
-
Hi Josh,
Thanks for reporting this. There haven’t been any similar reports so far, so I think it might be isolated to your installation/beaver builder.
A few questions:
- Can you use WP Rollback to install the previous version of Max Mega Menu and double check the issue is only present in the latest update? I can’t think of any changes in the latest update that would cause this.
- I take it you are adding the shortcode in a widget within a mega sub menu? What type of widget are you pasting the shortcode into? If you are using a text widget, you might need this code (depending on your theme): https://www.inmotionhosting.com/support/edu/wordpress/use-shortcodes-in-text-widget/.
Regards,
TomAnswer to Question 1:
I tried rolling back the update using Composer, but the issue persisted. The only solution that resolved it was the fix I implemented. My assumption is that the latest update may have introduced a database change that wasn’t reversed during the downgrade, though I didn’t investigate that further.Answer to Question 2:
We’re not using a text widget; we’re using an HTML widget to display the shortcode.-
This reply was modified 5 months, 1 week ago by
Josh.
Hi Josh,
There weren’t any database changes in the latest update for Max Mega Menu, so it seems like the issue wasn’t introduced in the latest update to Max Mega Menu. Given it was working before, it might have been caused by a theme update, a change in beaver builder or a change in the way the theme is setup (my guess is something has changed so the shortcode isn’t registered by the time the menu is processed).
If we get any other reports of shortcodes no longer working in the menu (we haven’t had any so far) I will take a closer look, right now I am not sure of the impact of applying ‘the_content’ filter to the widget output, it has not been necessary previously so I’d prefer not to add it to resolve an isolated case. I am glad you have found a solution that works for your setup.
Regards,
Tom
You must be logged in to reply to this topic.