You cannot use shortcodes directly in the menu URL on the menu page, as the brackets fail. But you can use placeholders as follows: #profile_link# .
Using the following code in functions.php you can create a custom menu item with the URL #profile_link# and it will replace it with your short code.
function my_dynamic_menu_items( $menu_items ) {
You just need to set the 'shortcode' to the $placeholders array and optionally 'atts' and 'content' .
For example, if your short code looks like this:
[example id="5" other="test"]Shortcode content[/example]
Would you update:
'#placeholder#' => array( 'shortcode' => 'example'; 'atts' => array( 'id' => '5', 'other' => 'test' ); 'content' => 'Shortcode content'; ),
Please note that I do not use do_shortcode() , because it is a resource-intensive function and is not suitable for work in this case.
source share