Smooth scrolling when clicking an anchor link
We might have a couple of hyperlinks on the post. Like for table of contents of sub headers of the posts. Using Anchor links, we can make the page scroll towards the anchor but this animation happens very fast. So how do we make this smooth?
There are some plugins that do this directly but i normally dont use plugin for this simple stuff. 
TLDR; We can paste the following script at the end of the body using plugins like `Header Footer Code Manager`
<script>document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); });});</script>- Long Version
- Install the plugin `Header Footer Code Manager` in your wordpress site. This plugin allows you to insert script on header or footer of your wordpress website.

- Go to your menu `HFCM` and click on `Add New`

- Add the scmooth scrolling script.
- Give you snippet a name for example `Smooth Scrolling Script`
- Choose Location as `footer`
- Copy paste the above script
- Hit the save button. and go back and check your posts where you have anchor link. It should be scrolling smoothly now.
Join FREE & Launch Your Business!
Exclusive Bonus - Offer Ends at Midnight Today
00
Hours
:
00
Minutes
:
00
Seconds
2,000 AI Credits Worth $10 USD
Build a Logo + Website That Attracts Customers
400 Credits
Discover Hot Niches with AI Market Research
100 Credits
Create SEO Content That Ranks & Converts
800 Credits
Find Affiliate Offers Up to $500/Sale
10 Credits
Access a Community of 2.9M+ Members
Recent Comments
0
Join FREE & Launch Your Business!
Exclusive Bonus - Offer Ends at Midnight Today
00
Hours
:
00
Minutes
:
00
Seconds
2,000 AI Credits Worth $10 USD
Build a Logo + Website That Attracts Customers
400 Credits
Discover Hot Niches with AI Market Research
100 Credits
Create SEO Content That Ranks & Converts
800 Credits
Find Affiliate Offers Up to $500/Sale
10 Credits
Access a Community of 2.9M+ Members
