• Resolved bheching

    (@bheching)


    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, 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)
  • 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:

    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 10 months, 1 week ago by wpmansour. Reason: removed unknown span
    Thread Starter bheching

    (@bheching)

    Hi wpmansour,

    thanks for your super fast response! I’m having a hard time to make the snippet work though.
    I added

    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 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

    (@vupdraft)

    We are just looking into this for you.

    smancuso95

    (@smancuso95)

    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:

    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

    (@wpmansour)

    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

    (@bheching)

    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.