1.0.0-alpha • Published 6 years ago

wp-barba-page-preloader v1.0.0-alpha

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

wp-barba-page-preloader

Barba.js wrapper for WordPress. Prefetches pages for faster load times. Specify a wrapper around the content that should change; everything outside this wrapper (e.g. your header and footer) stays static between page navigations.

Install

npm install wp-barba-page-preloader

OR

yarn add wp-barba-page-preloader

Usage

In your WordPress template files:

<div id="main-wrapper"><!-- Everything outside this wrapper stays between page navigations. -->
  <main class="main"><!-- Is replaced on page navigation with the content from the next page. -->
    This content changes on page navigation.
  </main>
</div>

In your WordPress theme's Javascript:

import initBarba from 'wp-barba-page-preloader';

window.addEventListener('load', () => {
  initBarba({
    pageloadFunctions: [],
    wrapperId: 'main-wrapper',
    containerClass: 'main',
    navLinkSelector: 'my-nav-links'
  });
});

The settings object.

KeyTypeRequiredDescriptionDefault
pageloadFunctionsarrayfalseAn array of functions to run after each page navigation.[]
wrapperIdstringtrueThe ID of an HTML wrapper around our main content area. Everything outside this container will stay static between page navigations. This ID must be in your template files.main-wrapper
containerClassstringtrueA CSS class attached to the HTML element that is replaced on page navigation. The CSS class must be present in your template files.main
navLinkSelectorstringfalseA string to select in-site navigation links that exist outside the wrapper. An active CSS class will be added to any selected link corresponding to the current page URL.

Warnings/Issues/To-Dos

-The Edit Post/Page link in the WP admin bar is not updated when navigating to a new page. One workaround is to hide that link with the admin_bar_menu hook and place the edit post link in a prominent position within the post.