landbryo
9/25/2017 - 6:06 PM

Enque Match Height in WordPress

This snippet allows you to use the jQuery Match Height plugin in your WordPress theme.

jQuery Match Height's files and documentation can be found here.

Create a file called match.js to house the matchHeight function:

jQuery(document).ready(function($) {

    $(function() {
        $('.match').matchHeight({
            byRow: true,
            property: 'height',
            target: null,
            remove: false
        });
    });
    
});

This code goes in your theme's functions.php to enqueue the matchHeight script as well as the script that initializes it.

function match_height_scripts() {
    if ( is_post_type_archive( 'issue' ) ) {
        wp_enqueue_script( 'match-script', get_stylesheet_directory_uri() . '/js/jquery.matchHeight-min.js', array( 'jquery' ) );
        
        wp_enqueue_script( 'match-custom-script', get_stylesheet_directory_uri() . '/js/match.js', array(), '1.0', true );
    }
}
add_action( 'wp_enqueue_scripts', 'match_height_scripts' );