Skip to content

Instantly share code, notes, and snippets.

@SuryawanshiPrajakta
Last active June 24, 2020 11:21
Show Gist options
  • Save SuryawanshiPrajakta/70a4e5bb022e5efeff70af66e670e134 to your computer and use it in GitHub Desktop.
Save SuryawanshiPrajakta/70a4e5bb022e5efeff70af66e670e134 to your computer and use it in GitHub Desktop.
Close Off-Canvas on click of a button
1. Add a custom class to the Button on which you want to close the off-canvas.
Refer - https://cl.ly/f61014b8265b
2. Paste below code in your active Themes Functions.php file -
function offcanvas_custom_script() {
?>
<script type="text/javascript">
jQuery(function($) {
$( '.custom-close-offcanvas' ).click( function () {
var $canvas = $( '.uael-offcanvas-show' ).attr( 'id' );
$canvas_id = $canvas.substring( $canvas.indexOf('-') + 1 );
OffCanvas._close( $canvas_id );
});
});
</script>
<?php
}
add_action( 'wp_footer', 'offcanvas_custom_script' );
Note - In the above code the "custom-close-offcanvas" will be replaced by the custom class you will add to the button.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment