This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

SPECIFIC PARAGRAPH

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #38555
    rafforaffo
    Participant

    hello, I have created some service pages that have links with anchors that, by clicking, lead you to a specific paragraph on the same page.

    I would like to know if with this plugin I can for example search for “online monitoring” and clicking will take me directly to the paragraph and not to the page …..

    Here a sample page: https://moellerip.com/our-service/anti-counterfeiting/

    a thousand thanks

    #38575
    Ernest MarcinkoErnest Marcinko
    Keymaster

    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
    }
    #38582
    rafforaffo
    Participant

    Hi, thanks for your reply, I followed all the steps you suggested, but I don’t see any changes in the search bar, the result seems the same to me as before. Am I wrong something?

    #38583
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    The configuration was incorrect, I corrected that, and the code was also missing from the snippets. I have added that, corrected the configuration, and tested like this: https://i.imgur.com/5vzStEM.png
    It seems to be working on my end, the page scrolls to the anchor. However this may not work in all cases though.

    #38585
    rafforaffo
    Participant

    thanks you so much

    #38593
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.