When a page is drawn, several get requests are received for loading images.

GET: mysite.loc/cat/page1.html GET: mysite.loc/cat/images/img1.jpg GET: mysite.loc/cat/images/img2.jpg ... 

Previously, the availability of image requests was simply determined through apache mod_rewrite . When defining a request for an image, the script replaces the headers with the necessary ones. Those. in .htaccess there was a rule:

 RewriteRule ^([a-zA-z0-9]+)/(.*\.(jpg|jpeg|png|gif))$ /mysript.php?imgpath=$1/$2 [NC,L] 

Rewriting the script as a plugin for WP, I encountered the problem that the engine does not store anything in the global $ _GET. In fact, the exact value of imgpath itself does not interest me, but it is necessary to know about its existence (or absence) in order to substitute headings at the right moment.

I tried to use the function add_rewrite_tag () built into wp api, but it did not help.

1 answer 1

get_query_var this function allows you to pull a get parameter

So parameters are registered

 function add_query_vars_filter( $vars ){ $vars[] = "my_var"; return $vars; } add_filter( 'query_vars', 'add_query_vars_filter' ); 

https://codex.wordpress.org/Function_Reference/get_query_var