- This topic has 7 replies, 2 voices, and was last updated 1 year, 5 months ago by
David.
-
AuthorPosts
-
January 4, 2021 at 7:24 am #1605106
Dennis
Hello,
I found out how to use Smooth Scroll GP, but I think there should also be an option without having to add a class to each anchor link, since for my editors it would be needed to edit the code in Gutenberg for links within a paragraph for example, which is the case for most cases.
What do you think?
Thanks,
DennisJanuary 4, 2021 at 7:28 am #1605109David
StaffCustomer SupportHi there
you can enable smooth scroll on all link elements with the PHP Snippet provided here:
https://docs.generatepress.com/article/generate_smooth_scroll_elements/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 4, 2021 at 11:12 pm #1605949Dennis
Thank you, this works perfectly!
January 5, 2021 at 4:21 am #1606255David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 15, 2021 at 8:22 am #1620235Dennis
Hey again.
I noticed a small issue with this example. Sometimes href=”#” is used for links with only javascript actions.
So I would like to extend the regex from the example: a[href*=”#”]How would this look, if after the #, there needs to be at least a letter. I do not really understand what syntax this is. Could you give me a hint here? In regex it would be something like .+
But why is there href*= anyways?Thanks for your great help!
January 15, 2021 at 9:49 am #1620373David
StaffCustomer SupportThe
*=
is a CSS wildcard selector. What it means is find me a href that contains a string in this case:#
character.
Unfortunately theres not a wild card that selects any old character in the string.If all your links started with the same letter/string for example they were
#section-X
then you could use:a[href*="#s"]
Geeky info here:
http://www.w3.org/TR/selectors/#attribute-substringsAlternatively if you can change the selector be more specific, and you could add multiple selectors to that filter:
add_filter( 'generate_smooth_scroll_elements', function( $elements ) { $elements[] = 'p > a[href*="#"]'; /* Only target A if direct child of P */ $elements[] = '.page-hero a[href*="#"]'; /* Target A if is inside the page-hero */ return $elements; } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/January 15, 2021 at 12:11 pm #1620528Dennis
wow nice. Thanks again for your help. This solves our issue.
January 16, 2021 at 4:54 am #1621096David
StaffCustomer SupportGlad to hear that!
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.