Hi @kelg7!
The solution is in the code snippet below.
You have two ways to add this code to your theme:
- Open the?
functions.php
?in your child theme and add the code at the end.
- ?or install the?Code Snippets?plugin and apply this code as a snippet.
After adding this code to your site, you still need to do one more thing. Change #search-results
to the ID or class assigned to the element containing the search results. It’s best to do this by right-clicking any element within the search results and selecting Inspect (Chrome). This will open the developer tool, allowing you to locate your ID/class. Please refer to this screenshot for assistance: [link]. Unfortunately, I can’t assist you further as I don’t know the URL of your site or the name of your theme.
// Scroll to the Search Results after the search results page loads
add_action( 'wp_footer', function() { ?>
<script type="text/javascript">
jQuery(document).ready(function() {
let urlParams = new URLSearchParams(window.location.search);
if(urlParams.has('dgwt_wcas')) {
var searchResults = jQuery('#search-results'); // Here you have to replace the search results container with your ID or class (for .class use . instead #).
if(searchResults.length > 0) {
var scrollToPosition = searchResults.offset().top - 80;
// Scroll to search results
jQuery('html, body').animate({
scrollTop: scrollToPosition
}, 1000); // Animation time
}
}
});
</script>
<?php }, 9999 );
Regards,
Kris