Skip to content

Instantly share code, notes, and snippets.

@nciske
Last active July 29, 2022 10:00
Show Gist options
  • Save nciske/5681384 to your computer and use it in GitHub Desktop.
Save nciske/5681384 to your computer and use it in GitHub Desktop.
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
Copy link

Thanks for this ;)

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