Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Filter nav menus to allow shortcodes in labels and domain agnostic URLs
// 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 ) );
function tester(){
return 'Worked!';

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