Archived topic
Anchor links issue with GPP
7 replies · Started by Dmitry on January 27, 2022
Hey!
When I have GPP plugin activated, my anchor links do not work properly. I can place a link to a specific place of a page Im currently at, but anchor links do not provide the opportunity to go from one page to another.
Ive made 2 example pages, so you can see how this glitch behave.
Hi there,
are you using any function to modify the GP Smooth Scroll behaviour ?
Yep,
Got this one in wp-head:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
// Store hash
var hash = this.hash;
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
</script>
What happens if you remove that?
Hmm... links ok, smooth scroll disabled. Any chance I can make them both work with GPP?
(GPP feature "Smooth scroll" Initiate smooth scroll on anchor links using the smooth-scroll class. - does not work that way)
Its that script that is the issue - it would do the same on any site GP or not.
And unfortunately have an alternative script for that. Personally i would just use the smooth-scroll that GP provides for on page links, and if the links comes from another page then it just won't be a smooth scroll
Thanks, David! I think it will be the best solution.
You're welcome