Skip to content

Loading a Custom Build of Modernizr

Jim Reevior edited this page Aug 14, 2018 · 1 revision

Loading a Custom Build of Modernizr

Responsive Framework comes with a build of Modernizr that will be sufficient for most sites. If a site requires additional (or less) Modernizr checks, it is possible to load a custom build of Modernizr.

Before loading a custom Modernizr build, think of this question. Would this reasonably benefit every site using Responsive Framework? If the answer is yes, then a pull request should be opened on Responsive Framework instead of using the following approach.

<?php

/**
 * Set the Modernizr version constant to our custom build version.
 */
define( 'RESPONSIVE_MODERNIZR_VERSION', '3.5.1' );

/**
 * Prevent Responsive Framework from enqueueing the version of Modernizr it ships with.
 */
add_filter( 'r_enqueue_modernizr', '__return_false' );

/**
 * Load a custom build of Modernizr.
 */
function mytheme_enqueue_scripts() {
	wp_enqueue_script( 'modernizr', get_stylesheet_directory_uri() . "/path/to/modernizr.min.js", array(), RESPONSIVE_MODERNIZR_VERSION );
}
add_action( 'wp_enqueue_scripts', 'mytheme_enqueue_scripts' );

To ensure that Modernizr is loaded before responsive-scripts (the framework's primary JavaScript file), modernizr also needs to be re-added as a dependency.

<?php
/**
 * Add Modernizr as a dependency of `responsive-scripts`.
 */
function mytheme_r_script_dependencies( $dependencies ) {
	$dependencies[] = '';

	return $dependencies;
}
add_action( 'r_script_dependencies', 'mytheme_r_script_dependencies' );

Welcome to Responsive!

Get started

Configuration

Build child themes

Sass

Javascript

PHP

Shortcodes

Templates

GitHub

Tasks

Contribute to the framework

Code Examples

BU Developer Resources

Clone this wiki locally