Fitty, Snugly text resizing
Scales up (or down) text so it fits perfectly to its parent container. Ideal for flexible and responsive websites.
- https://github.com/rikschennink/fitty
- https://wordpress.stackexchange.com/questions/340435/add-javascript-library-fitty-to-wordpress
- First you have to make a child theme of your current theme.
- Then, in your child theme create a
functions.php
file - Create a
js
folder and putfitty.min.js
inside it and create achild.js
file also inside thisjs
folder - In functions.php of your child theme add the following :
<?php // Opening PHP tag - nothing should be before this, not even whitespace
function child_scripts() {
wp_enqueue_script( 'fitty', get_theme_file_uri( '/js/fitty.min.js' ), array(), filemtime( get_theme_file_path( '/js/fitty.min.js' ) ), true );
wp_enqueue_script( 'child', get_theme_file_uri( '/js/child.js' ), array( 'jquery' ), filemtime( get_theme_file_path( '/js/child.js' ) ), true );
}
add_action( 'wp_enqueue_scripts', 'child_scripts' );
In child.js add the following :
(function ($) {
fitty('#my-element'); // Here fitty is targeting the element with an id='my-element'
})(jQuery);