Quick Tip: Script Debugging in WordPress

If you’re debugging core WordPress scripts, one thing you might run into is dealing with cached copies of the script. Due to how script-loader.php enqueues the core files, their versions are “hard coded” and short of editing script-loader.php as well, there’s a way to fix this via a filter:

add_filter( 'script_loader_src', function( $src, $handle ) {
     if ( false !== strpos( $src, 'ver=' ) ) {
         $src = remove_query_arg( 'ver', $src );
         $src = add_query_arg( array( 'ver', rawurlencode( uniqid( $handle ) . '-' ) ), $src );
     }
     
     <span style="background-color: inherit; color: rgb(248, 248, 242); font-size: inherit; letter-spacing: -0.015em;">return $src;</span>
 }, -1, 2 );Code language: PHP (php)

This will apply a unique ver argument to the core scripts on each refresh, so no matter what you’re editing you should get the most recent version from both any page cache you may have and also the browser cache (🤞).

Also, don’t forget to enable SCRIPT_DEBUG if you’re hacking away at core scripts to debug issues.

I couldn’t find a good related image, so enjoy this delicious toilet paper.

Other Posts Not Worth Reading

Hey, You!

Like this kind of garbage? Subscribe for more! I post like once a month or so, unless I found something interesting to write about.


Comments

Leave a Reply