LiteSpeed - register WordPress menu as ESI block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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