Ajaxify Your WordPress _s (Underscores) Theme With This Code

Ajaxify _s

I’ve created a modified version of the Browserstate (History.js) Ajaxify plugin that works with _s (Underscores). In order for this to work, you’ll need to use wp_enqueue_script() to include the History.js and scrollTo libraries, as well as my modified Ajaxify script. Do this in your existing enqueue function. If you don’t know what that means, check out this article.

wp_enqueue_script( 'scrollto', '//balupton.github.io/jquery-scrollto/lib/jquery-scrollto.js', array( 'jquery' ), '', true );
wp_enqueue_script( 'history-js', '//browserstate.github.io/history.js/scripts/bundled/html4+html5/jquery.history.js', array(), '', true ); 
wp_enqueue_script( 'ajaxify', '//raw.githubusercontent.com/AbacusPowers/ajaxify/master/ajaxify-html5.js', array( 'jquery' ), '', true ); 

Above, you’ll find the lines to include, if you want to load these libraries remotely. I would recommend, however, that you actually take the time to download them, and use a filepath specific to your theme. You can use something like

wp_enqueue_script( 'ajaxify', get_template_directory_uri() . '/js/vendor/ajaxify/ajaxify-html5.js', array( 'jquery' ), '', true );

instead of the direct link to the library on GitHub. To get you started, here’s a direct link to the Ajaxify file download.

Note: The menu update only works for the ‘current-menu-item’ class, at the moment. Ideally, this would be modified to also update any parent or children menu classes as well.

2 thoughts on “Ajaxify Your WordPress _s (Underscores) Theme With This Code

  1. Thanks a lot for this modified version of Ajaxify. I’m trying to integrate it with my _s template, but the scroll-to plugin doesn’t seem to work. My menu has a fixed position so when I scroll then I click a link in the menu it opens the content with the same scroll position. I don’t really understand why because the scroll-to plugin is enqueue in my function.php as History and Ajax. Did you experience this problem?

  2. Had I found this article about 3 hours ago, I wouldn’t have posted on the development forum. Downloaded all scripts to my theme folder and it worked the very first time!

    Thank you muchly!

Leave a Reply