• Resolved mcdeth

    (@mcdeth)


    Hello, when a user filters by color, I want to dynamically change the Rank Math title, remove the canonical, and modify the meta description accordingly. However, this doesn’t work if I try to make these changes within a function:


    add_action('woocommerce_before_shop_loop', 'display_current_filter', 1000);
    add_action('woocommerce_before_shop_loop', 'display_current_filter', 1);



    function display_current_filter() {
    global $wp_query;

    if (!empty($wp_query->query_vars['filter_color'])) {
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {

    return false;

    });
    }
    return false;
    }

    This could work if I modify display_current_filter function, but then I have to call same function at least 5 times (for title, description etc). Is there any way to run these inside a function?

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    if(display_current_filter()) return false;
    return $canonical;

    });

Viewing 1 replies (of 1 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @mcdeth,

    Thank you for contacting Rank Math support.

    Our filters will not work inside the function. You can try using the condition directly inside the filter instead of calling the function:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    global $wp_query;
    if (!empty($wp_query->query_vars['filter_color'])) { return false; }
    return $canonical;

    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.