Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Filter nav menus to allow shortcodes in labels and domain agnostic URLs
<?php
// Add a custom menu item with the URL "_SITEURL_/test" and label "[test]" to see it in action
add_filter('wp_nav_menu', 'menu_shortcodes');
function menu_shortcodes( $menu ){
return str_replace('_SITEURL_',preg_replace("~^(?:f|ht)tps?://~i", '', home_url() ), do_shortcode( $menu ) );
}
add_shortcode('test','tester');
function tester(){
return 'Worked!';
}
@jemoreto

This comment has been minimized.

Copy link

@jemoreto jemoreto commented Feb 19, 2017

Thanks for this ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment