WordPress 5.5 – jQuery Migrate Fixes and Pagination Fixes

Photo of a book
Photo by BENCE BOROS on Unsplash

Before I start this article, I do want to state that I know there are two logo images. I’ll them shortly, or stop procrastinating on my re-design transitioning away from Beaver Builder to just straight Gutenberg. </siderant>

WordPress 5.5 Broke jQuery on Many Sites

If you are on WordPress 5.5 and having site issues involving JavaScript (page not loading, toggles not working, scripts erroring out), it is likely because of the jQuery Migrate issue in WordPress 5.5.

A quick fix is to install the Enable jQuery Migrate Helper plugin on affected sites:

A quick fix for WordPress plugin/theme authors is to include jquery-migrate as one of their script dependencies when you are enqueueing your scripts.

array( 'jquery', 'jquery-ui-dialog', 'jquery-migrate', )
Code language: PHP (php)
WordPress JS Authors: Add jquery-migrate as a script dependency for a temporary band-aid.
Click to Share

The jQuery Migrate Helper plugin is a long-term solution, but will not help in the long-term. The goal is to bring jQuery in WordPress up-to-date gradually.

The first step was removing jquery-migrate in WP 5.5. The script is still “there”, so you can still enqueue it. It isn’t until WordPress 5.7 that jQuery Migrate will actually disappear from core. So you have until WP 5.7 to figure out where your JS code is failing and fix it long-term. We don’t want to rely on a “helper” plugin to fix every site in existence, but we can do our part to make jquery-migrate a thing of the past.

BTW, if you do write a WP CLI tool that’ll scan files and point where the jQuery Migrate issues are, you will be Internet famous. At least in my book.

Breaking Pagination

A more WordPress 5.5 issue, that isn’t really fixable, is pagination.

Pagination being broken was brought to my attention by one of the users of my plugin.

Not sure if it helps but pagination appears to have affected many sites with the update to wordpress 5.5

There is an official bug report here:

But WordPress developers say that it is theme and plugin developers that are using the variable ‘page’ incorrectly.

Anyway, don’t know if this is involved or not but thought it might help.

fatherb

My first reaction was crap. WordPress 5.5 broke pagination, and I thought I was using it right my entire career. I was apparently wrong.

The pagination issue at play is this type. of query, which worked in WP 5.4.

This can be duplicated by creating a bunch of dummy posts, creating a page, and assigning it as the homepage for the site with pretty permalinks enabled.

In the theme, according to the template hierarchy, I created a file named front-page.php and stripped out most of the fluff. For this example, I’ll piick on the Twenty Twenty theme.

<?php get_header(); ?> <main id="site-content" role="main"> <?php echo "Hi there front page."; ?> </main><!-- #site-content --> <?php get_footer();
Code language: PHP (php)

Now let’s do some basic query code to query some posts and get pagination to work.

<?php get_header(); ?> <main id="site-content" role="main"> <?php $my_page = 0; if ( absint( get_query_var( 'paged' ) > 1 ) ) { $my_page = absint( get_query_var( 'paged' ) ); } $post_args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 10, 'paged' => $my_page, ); $my_query = new WP_Query( $post_args ); if ( $my_query->have_posts() ) { while ( $my_query->have_posts() ) { $my_query->the_post(); echo get_the_title() . '<br />' ; } } echo paginate_links( array( 'total' => $my_query->max_num_pages, 'current' => max( 1, get_query_var( 'paged' ) ), 'format' => 'page/%#%', 'show_all' => false