Skip to content

Instantly share code, notes, and snippets.

@Narga
Created August 27, 2013 01:10
Show Gist options
  • Save Narga/6348594 to your computer and use it in GitHub Desktop.
Save Narga/6348594 to your computer and use it in GitHub Desktop.
WordPress Jetpack snippets
/*
* Check if Jetpack Modules Are Enabled
* carousel
* contact-form
* custom-css
* gravatar-hovercards
* infinite-scroll
* minileven (mobile theme)
* sharedaddy
* shortcodes
* widgets
* See: http://wwww.narga.net/how-to-make-your-theme-support-jetpacks-infinite-scroll-feature/
*/
if ( class_exists( 'Jetpack', false ) ) {
$jetpack_active_modules = get_option('jetpack_active_modules');
if ( class_exists( 'Jetpack', false ) && $jetpack_active_modules && in_array( 'your-module', $jetpack_active_modules ) ) {
// Do something
}
}
/*
* Another check JetPack module
* Jetpack::is_module_active()
* See: http://wwww.narga.net/how-to-make-your-theme-support-jetpacks-infinite-scroll-feature/
*/
if( class_exists( ‘Jetpack’ ) && in_array( ‘contact-form’, Jetpack::get_active_modules() ) {
# Do something
}
/*
* JetPack Infinite Scroll + Masonry
* See: http://wwww.narga.net/how-to-make-your-theme-support-jetpacks-infinite-scroll-feature/
* Disable URL PushState with:
* 'wrapper' => false,
* 'render' => false,
*/
jQuery( document ).ready( function( $ ) {
infinite_count = 0;
// Triggers re-layout on infinite scroll
$( document.body ).on( 'post-load', function () {
infinite_count = infinite_count + 1;
var $container = $('#content');
var $selector = $('#infinite-view-' + infinite_count);
var $elements = $selector.find('.hentry');
$elements.hide();
$container.masonry( 'reload' );
$elements.fadeIn();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment