Home › Forums › Support › Exclude some anchor link from smooth scrool when using function.php solution
- This topic has 7 replies, 2 voices, and was last updated 3 years, 2 months ago by
David.
-
AuthorPosts
-
February 18, 2023 at 4:11 am #2537775
Antonio
Hello,
I’ve applied the following solution to have the smooth scroll behavior applied to all anchor links:add_filter( ‘generate_smooth_scroll_elements’, function( $elements ) {
$elements[] = ‘a[href*=”#”]’;return $elements;
} );This will generate some problems with navigation links in slider plugins (i.e. Smart Slider 3) as when the next/before navigation button is clicked, the page will in some case scroll to the top of the page.
I tried to exclude all the links not containing a particular string (i.e. #top), so I did the following:
add_filter( ‘generate_smooth_scroll_elements’, function( $elements ) {
$elements[] = ‘a[href*=”#”]:not(a[href*=”#top”])’;return $elements;
} );But this is not working (I assume it’s because the href*=”#”] condition is true for every “#top” anchor link.
What is the correct way to exclude some anchor links from the function? Could you please make 2 examples where:
– on the first example: all href*=”#” links are targeted, excluding links containing “#top”
– on the second: all href*=”#” links are targeted, excluding links containing “#top” AND “#middle”Thank you
February 18, 2023 at 4:45 am #2537805David
StaffCustomer SupportHi there,
where are the Links on your site that you want Smooth Scroll to apply to ?
February 18, 2023 at 4:56 am #2537809Antonio
Hi David,
take a look here: https://party.lacasadimelo.com/en/la-casa-di-melo-organic-farm-hotel/Scroll to the slider under “From Sicily with love” heading and try to click on navigation (https://prnt.sc/wIQQB1bM3i7H).
Thank you
February 18, 2023 at 6:52 am #2537894David
StaffCustomer SupportAs those links have a
role=buttonattribute, we can try excluding the role from the link. So try this selector.a[href*=”#”]:not([role])February 18, 2023 at 6:58 am #2537901Antonio
Hi,
it works, thanks!What if I need to exclude other anchors with a role attribute?
Thank youFebruary 18, 2023 at 7:34 am #2537946David
StaffCustomer SupportThat selector will exclude any anchor with any
rolenot just button.
Is that ok?February 18, 2023 at 8:33 am #2538105Antonio
Hi David,
it’s ok. Problem is: if I find other anchors to fix, then I’ll have to open a new ticket.
Anyway, for the moment this solution works for me.
Thank you!February 18, 2023 at 9:34 am #2538153David
StaffCustomer SupportIf you find any, let us know, as its hard to create a wild card selector that omits some elements without seeing them.\
Glad to be of help. -
AuthorPosts
- You must be logged in to reply to this topic.