Skip to content

Instantly share code, notes, and snippets.

@landbryo
Last active May 24, 2018 16:14
Show Gist options
  • Save landbryo/1e738d793d05bc81cc5901869aecefab to your computer and use it in GitHub Desktop.
Save landbryo/1e738d793d05bc81cc5901869aecefab to your computer and use it in GitHub Desktop.
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment