Skip to content

Instantly share code, notes, and snippets.

@robertstaddon
Created January 8, 2020 00:51
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/bf9c299fc4d103785ed5833b02d6a8d6 to your computer and use it in GitHub Desktop.
Save robertstaddon/bf9c299fc4d103785ed5833b02d6a8d6 to your computer and use it in GitHub Desktop.
LiteSpeed - register WordPress menu as ESI block
<?php
add_action( 'init', function() {
if ( method_exists( 'LiteSpeed_Cache_API', 'esi_enabled' ) && LiteSpeed_Cache_API::esi_enabled() ) {
LiteSpeed_Cache_API::hook_tpl_not_esi( function () {
add_filter( 'wp_nav_menu', function( $nav_menu_html, $args ) {
if ( $args->menu_id == "menu-id-to-replace" ) {
return LiteSpeed_Cache_API::esi_url( 'my_custom_menu_esi_hook', 'My Menu to Use with ESI' );
}
return $nav_menu_html;
}, 10, 2 );
} ) ;
LiteSpeed_Cache_API::hook_tpl_esi( 'my_custom_menu_esi_hook', function ( ) {
wp_nav_menu( array(
'menu_id' => 'menu-id-to-replace'
) );
}) ;
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment