Skip to content

Instantly share code, notes, and snippets.

@solid-pixel
Created June 30, 2016 12:28
Show Gist options
  • Save solid-pixel/2e30cc9262da4b45d047a46ffd829adc to your computer and use it in GitHub Desktop.
Save solid-pixel/2e30cc9262da4b45d047a46ffd829adc to your computer and use it in GitHub Desktop.
Smooth Scroll Wordpress Plugin
<?php
/**
* Plugin Name: Smooth Scroll
* Plugin URI: http://
* Description: Smooth scroll for anchor links
* Version: 1.0.0
* Author:
* Author URI: http://
* License: GPL2
*/
add_action('wp_footer','smoothscroll');
function smoothscroll() {
print("<script>jQuery(function() {
jQuery.easing.myEasing = function (x, t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -12 * t/d) + 1) + b;
}
jQuery('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = jQuery(this.hash);
target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
if (target.length) {
jQuery('html,body').animate({
scrollTop: target.offset().top
}, 1000,'myEasing');
return false;
}
}
});
});</script>");
}
@solid-pixel
Copy link
Author

Smooth Scroll plugin for Wordpress

Installation:

  1. Create the folder "smooth-scroll" under wp-content/plugins
  2. Upload smooth-scroll.php to the folder you just created
  3. Enable the plugin in the backend
  4. (optional) Fine-tune the code according to your needs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment