Title: Ignoring query strings
Last modified: May 13, 2024

---

# Ignoring query strings

 *  Resolved [bheching](https://wordpress.org/support/users/bheching/)
 * (@bheching)
 * [2 years ago](https://wordpress.org/support/topic/ignoring-query-strings/)
 * Hi there,
 * we get a lot of referral traffic with query strings in the url and wonder if 
   it is possible to configure WP-Optimize (free) to completely ignore these. Since
   none of our content depends on query params we want all visitors getting served
   from cache.
 * In [another thread](https://wordpress.org/support/topic/ignoring-some-query-variables/),
   a filter hook called “wpo_cache_ignore_query_variables” was mentioned but it 
   doesn’t seem to work. Does this hook even exist? Are there other hooks, we could
   use?
 * Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [wpmansour](https://wordpress.org/support/users/wpmansour/)
 * (@wpmansour)
 * [2 years ago](https://wordpress.org/support/topic/ignoring-query-strings/#post-17750262)
 * Hello,
 * I understand you’d like to configure WP-Optimize to ignore certain query parameters
   so that all visitors get served from the cache, irrespective of the query strings
   in the URL. You can indeed accomplish this by utilizing the available `wpo_cache_ignore_query_variables`
   filter hook.
 * Here’s how you can customize this hook to include specific query parameters that
   should be ignored by the cache:
 *     ```wp-block-code
       function custom_wpo_cache_ignore_query_variables($exclude) {
           $new_variables = array('your_query_var1', 'your_query_var2'); 
           $exclude = array_merge($exclude, $new_variables);
           return $exclude;
       }
       add_filter('wpo_cache_ignore_query_variables', 'custom_wpo_cache_ignore_query_variables');
       ```
   
 * Please replace `'your_query_var1'` and `'your_query_var2'` with the actual query
   parameters you want WP-Optimize to ignore. Add this code to your theme’s `functions.
   php` file or a custom plugin.
 * This adjustment will ensure that these query parameters do not prevent pages 
   from being served from cache, thereby potentially improving your site’s performance
   for users who visit your site via referral links that include these parameters.
 * Let us know if you have any further questions or need assistance. We’re here 
   to help!
 * Best regards,
   Mansour M
    -  This reply was modified 2 years ago by [wpmansour](https://wordpress.org/support/users/wpmansour/).
      Reason: removed unknown span
 *  Thread Starter [bheching](https://wordpress.org/support/users/bheching/)
 * (@bheching)
 * [2 years ago](https://wordpress.org/support/topic/ignoring-query-strings/#post-17751391)
 * Hi wpmansour,
 * thanks for your super fast response! I’m having a hard time to make the snippet
   work though.
   I added
 *     ```wp-block-code
       function custom_wpo_cache_ignore_query_variables( $exclude ) {
           $new_variables = array('utm_source', 'utm_campaign', 'fbclid');
           $exclude = array_merge($exclude, $new_variables);
           return $exclude;
       }
       add_filter('wpo_cache_ignore_query_variables', 'custom_wpo_cache_ignore_query_variables');
       ```
   
 * to the Themes’ functions.php, flushed WPO-Cache and visited **mydomain.com/?fbclid
   =1** in an Incognito Tab.
 * The result was (WP-Debug enabled):
 *     ```wp-block-code
       <!-- WP Optimize page cache - https://getwpo.com - Page not served from cache because: In the settings, caching is disabled for matches for one of the current request's GET parameters -->
       ```
   
 * I then tried adding the Snippet via WPCode and via muplugin – with the same result.
   Changing the Theme to Twenty Twenty-Four didn’t help either.
   So maybe i’m missing
   sth.? Any ideas why it’s not working?
 * Best regards!
 *  Plugin Support [vupdraft](https://wordpress.org/support/users/vupdraft/)
 * (@vupdraft)
 * [2 years ago](https://wordpress.org/support/topic/ignoring-query-strings/#post-17759935)
 * We are just looking into this for you.
 *  [smancuso95](https://wordpress.org/support/users/smancuso95/)
 * (@smancuso95)
 * [2 years ago](https://wordpress.org/support/topic/ignoring-query-strings/#post-17773203)
 * I had the same result as OP:
 * Page not served from cache because: In the settings, caching is disabled for 
   matches for the current URL
 * My code:
 *     ```wp-block-code
       function mncs_wpo_cache_ignore_query_variables( $exclude ): array {
       $new_variables = [
       'fbclid',
       'gclid',
       'gclsrc',
       'dclid',
       'gbraid',
       'wbraid',
       'twclid',
       'yclid',
       'utm_content',
       'utm_term',
       'utm_campaign',
       'utm_medium',
       'utm_source',
       'utm_id',
       'utm_source_platform',
       'utm_creative_format',
       'utm_marketing_tactic',
       '_ga',
       '_gl',
       'mc_cid',
       'mc_eid',
       '_bta_tid',
       '_bta_c',
       'trk_contact',
       'trk_msg',
       'trk_module',
       'trk_sid',
       'gdfms',
       'gdftrk',
       'gdffi',
       '_ke',
       '_kx',
       'redirect_log_mongo_id',
       'redirect_mongo_id',
       'sb_referer_host',
       'mkwid',
       'pcrid',
       'ef_id',
       's_kwcid',
       'msclkid',
       'dm_i',
       'epik',
       'pk_campaign',
       'pk_kwd',
       'pk_keyword',
       'piwik_campaign',
       'piwik_kwd',
       'piwik_keyword',
       'mtm_campaign',
       'mtm_keyword',
       'mtm_source',
       'mtm_medium',
       'mtm_content',
       'mtm_cid',
       'mtm_group',
       'mtm_placement',
       'matomo_campaign',
       'matomo_keyword',
       'matomo_source',
       'matomo_medium',
       'matomo_content',
       'matomo_cid',
       'matomo_group',
       'matomo_placement',
       'hsa_cam',
       'hsa_grp',
       'hsa_mt',
       'hsa_src',
       'hsa_ad',
       'hsa_acc',
       'hsa_net',
       'hsa_kw',
       'hsa_tgt',
       'hsa_ver',
       '_branch_match_id',
       'mkevt',
       'mkcid',
       'mkrid',
       'campid',
       'toolid',
       'customid',
       'igshid',
       'si',
       'sms_source',
       'sms_click',
       'sms_uph',
       'ttclid',
       'ndclid',
       'ScCid',
       'rtid',
       'irclickid'
       ];
   
       return array_merge( $exclude, $new_variables );
       }
   
       add_filter( 'wpo_cache_ignore_query_variables', 'mncs_wpo_cache_ignore_query_variables' );
       ```
   
 * Regards!
 *  [wpmansour](https://wordpress.org/support/users/wpmansour/)
 * (@wpmansour)
 * [2 years ago](https://wordpress.org/support/topic/ignoring-query-strings/#post-17773539)
 * Thank you for your patience. Here is an update regarding the issue with ignoring
   specific query parameters for caching.
 * This feature is **not supported** in the **free version of WP-Optimize** because`
   advanced-cache.php` is executed before MU-plugins are loaded. This prevents the
   necessary filters from being applied in time.
 * However, the premium version supports this functionality as it loads extensions
   with `advanced-cache.php`, ensuring that the filters are applied correctly.
 *  Thread Starter [bheching](https://wordpress.org/support/users/bheching/)
 * (@bheching)
 * [2 years ago](https://wordpress.org/support/topic/ignoring-query-strings/#post-17774001)
 * Thank you for looking into into my issue and your detailed explanation! Will 
   consider upgrading then.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Ignoring query strings’ is closed to new replies.

 * ![](https://ps.w.org/wp-optimize/assets/icon-256x256.png?rev=1552899)
 * [WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance](https://wordpress.org/plugins/wp-optimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-optimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-optimize/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-optimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-optimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-optimize/reviews/)

 * 6 replies
 * 4 participants
 * Last reply from: [bheching](https://wordpress.org/support/users/bheching/)
 * Last activity: [2 years ago](https://wordpress.org/support/topic/ignoring-query-strings/#post-17774001)
 * Status: resolved