Add shortcode to a custom link in navigation menu

Is it possible to add a shortcode to a custom link in a menu? I have a custom link in the menu. Under this link is the link for the page of Messages. There is a shortcode to show the number of messages. Is it possible to add the shortcode on the"My M" or to the link of the page of Messages.

Thanks

Hi There,

That would not be possible out of the box, it might be possile with Custom development but would be out of the scope of our support.

If you decide to use PRO instead of X you could add a shortcode to your header and build really creative headers.

Hope it helps

Hi Joao,

I have upgraded to Pro. My old header got imported successfully. Now what do I need to add the shortcode to the link. Please advise.

Thanks

Hi there,

You can’t really add shortcodes to menu link, but you can add this code to your child theme’s functions.php to enable shortcode for menu links.

add_filter( 'nav_menu_link_attributes', 'enable_link_shortcodes', 9999999, 3 );

function enable_link_shortcodes( $atts, $item, $args ) {
    $atts['href'] = do_shortcode( $atts['href'] );
    return $atts;
}

Then simply add your shortcode like http://example.com/[shortcode_here]/is/awesome/

Cheers!

Thank you Rad. Not sure where to add this link/shortcode
http://example.com/[shortcode_here]/is/awesome/

I was also reading do_shortcode is a resource intensive function, is that true?

Hello There,

You need to edit your menu in Appearance > Menus. Please see the image below:

Hope this helps.

This did not work but its ok I found an alternate solution. Thank you for all the help and support.

Hello @Mangtum,

We are just glad that you have figured it out a way to correct the said issue.
Thanks for letting us know!

Best Regards.