Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › SPECIFIC PARAGRAPH › Reply To: SPECIFIC PARAGRAPH
Hi,
Well, there is a keyword highlighter feature, which can scroll to the first match of the keywords on the matching page. If the match is within the desired paragraph, then it should be able to scroll there automatically.
Searching the anchor and clicking it however is not going to work. That definitely needs custom coding to recognize the anchors and click them when needed.
I have coded a possible quick solution for you, but I don’t know if it works. Please set this exact keyword highlighter configuration first.
Add this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_action('wp_footer', 'asp_footer_custom_script', 999999);
function asp_footer_custom_script() {
?>
<script>
jQuery(function($){
setTimeout(function(){
let $parent = $('span[class*=asp_single_highlighted]').first().closest('a');
if ( $parent.is('a') && $parent.attr('href').indexOf('#') == 0 ) {
$parent.get(0).click();
}
}, 500);
});
</script>
<?php
}