• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

RESOLVED Use shortcode on Menu Field

akrinis

New member
Messages
1
Likes
0
Points
1
#1
Hey,
I made my first PHP snippet and I put it on a page and it works as it should be.
But my main purpose is to use it into a menu element as a shortcode. I have already used another shortcode from another plugin and I know that it can works.
However, when I insert the shortcode from your plugin, nothing happens.

Can you help me please, how to enable it to work also inside a menu element?

Thanks in advance!
 

Attachments

Kirill

Support team
Messages
82
Likes
4
Points
8
#2
Hi
Currently our plugin does not support this feature.To solve this problem you need add following code somewhere. The file function.php is suitable for this. Recommended use child theme.

PHP:
add_filter( 'nav_menu_link_attributes', 'insert_php_in_menu', 10, 4 );
function insert_php_in_menu($atts, $item, $args, $depth ){
    if(strrpos($atts['href'], 'wbcr_') !== false){
        $url = $atts['href'];

        // remove auto appended "http://"
        $url = preg_replace('#^(http(|s):\/\/)#', '', $url);

        $url = urldecode($url);
        $url = do_shortcode($url);
        $atts['href'] = $url;
    }
    return $atts;
}
Best regards