Skip to content

Instantly share code, notes, and snippets.

@robertstaddon
Last active October 30, 2022 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertstaddon/fb4fb122fa22261d9c666400fca3cb39 to your computer and use it in GitHub Desktop.
Save robertstaddon/fb4fb122fa22261d9c666400fca3cb39 to your computer and use it in GitHub Desktop.
Turn a WordPress Menu into a LiteSpeed ESI Block
<?php
add_filter( 'wp_nav_menu', function( $nav_menu_html, $args ) {
if ( $args->menu_id == "menu-id-to-replace" ) {
if ( apply_filters( 'litespeed_esi_status', false ) )
return apply_filters( 'litespeed_esi_url', 'my-esi-menu', 'Navigation Menu', array( 'nav_menu_html' => $nav_menu_html, 'args' => $args ), $control = 'private,no-vary', $silence = false );
}
return $nav_menu_html;
}, 10, 2);
add_action( 'litespeed_esi_load-my-esi-menu', function ( $atts ) {
echo $atts['nav_menu_html'];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment