[wp-trac] [WordPress Trac] #34699: New function: `get_query_arg()`

WordPress Trac noreply at wordpress.org
Wed Mar 2 09:27:21 UTC 2016


#34699: New function: `get_query_arg()`
-------------------------------------+------------------------------
 Reporter:  sebastian.pisula         |       Owner:
     Type:  enhancement              |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  General                  |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  close reporter-feedback  |     Focuses:
-------------------------------------+------------------------------

Comment (by bastho):

 Hi,

 I just have an use case:

 - Query strings in static source URLs are not the best for performances
 - Version parameter is very useful to prevent from unwanted browser cache

 Someone (me) could want to hook into `script_loader_src` in order to move
 the version from query string to path.

 example:

 http://example.com/wp-includes/js/jquery/jquery.js?ver=4.4.2

 would become:

 http://dev.eelv.fr/wp-includes/js/jquery/jquery-4.4.2.js

 for this, I would use something like that:

 {{{#!php
 <?php

 add_filter( 'style_loader_src', 'remove_wp_ver_par', 9999 );
 add_filter( 'script_loader_src', 'remove_wp_ver_par', 9999 );
 function remove_wp_ver_par( $src ) {
     if ( null !== $ver = get_query_arg( 'ver', $src) ){
         $src = preg_replace( '/\.(js|css)$/', '-_'.$ver.'.$1',
 remove_query_arg( 'ver', $src ));
     }
     return $src;
 }
 }}}



 With the appropriate htaccess/nginx rules, it does the trick.

 Actually, I could do it another way but this is the lighter way.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34699#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list