I know this question was asked several years ago but to help solve this issue with modals close button not functioning after print dialog, here is a very simple solution I ended up with.
STEP 1: Add a display property d-print-none
as a class to all elements you don't want in the print layout.
STEP 2: Create a <div id="printable-contents">
and add a display property d-print-block
to it
STEP 3: Use this function which is a modified version of the function you are already using to print your elements. NB: You can pass your modal id to the function, hide it, print and then show it to the user
function printElements(element,modal) {
$('.modal').modal('hide'); //Hide all modals to prevent greying out contents
var printContents = document.getElementById(element).innerHTML; // Get printable contents
$('#printable-content').html(printContents); // Populate the printable element
// Wait a while a print your contents
setTimeout(function(){
window.print();
$('#printable-content').html(''); // Clear the printable contents
$('#'+modal).modal('show'); // Show the modal
},250);
};
Link to display property classes as exampled by Bootstrap 5