Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.