Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Question marks stop ‘Scroll to first keyword match’ from working › Reply To: Question marks stop ‘Scroll to first keyword match’ from working
April 16, 2026 at 11:10 am
#57312
Keymaster
Hi Stuart,
I see. I am not sure if this should be patched, as I feel this should be intentional for most cases, but I will definitely consider it.
You can actually fix this through a code snippet, but as you noticed this is on the client side, not on the server side. This should do the trick:
add_action('wp_footer', function () {
?>
<script>
window.addEventListener("load", () => {
document.querySelectorAll(".asp_main_container").forEach((el) => {
el.addEventListener("asp_results_show", (event) => {
// event.detail carries the arguments
const [id, instance] = event.detail;
document.querySelectorAll(".asp_r_" + id + '_' + instance + ' .asp_res_url').forEach((el)=>{
const url = new URL( el.getAttribute('href') );
let phrase = url.searchParams.get('asp_highlight');
if ( phrase !== null ) {
phrase = phrase.replace(/[!?]/g, '');
url.searchParams.set('asp_highlight', phrase);
el.setAttribute('href', url.href);
}
});
});
});
});
</script>
<?php
});