• Resolved porshegt9

    (@porshegt9)


    Hello

    For some reason, on the whole website, if I add variable %page% to the title or description, on the frontend it adds “-” before it.

    For example, I have a standard setting for search results:

    %search_query% %page% %sep% %sitename%

    But on frontend I see:

    query – Page 2 of # – WEBSITETITLE

    Same issue everywhere I add %page%. Why it adds separator?

    How to fix it?

    Thanks.

    • This topic was modified 1 month, 2 weeks ago by porshegt9.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Jeremy

    (@jeremrm)

    Hello @porshegt9,

    Thank you so much for getting in touch.

    What you’re experiencing is actually the expected behavior. In Rank Math, the %page% variable automatically includes a separator when it’s output on the frontend, which is why you’re seeing the extra “–” before the pagination text.

    To avoid this and have more control over the output, you can use a custom variable instead of %page%. You can add the following filter to your site:

    add_action('rank_math/vars/register_extra_replacements', function () {
    rank_math_register_var_replacement(
    'custom_page',
    [
    'name' => esc_html__('Author name', 'rank-math'),
    'description' => esc_html__('Author description', 'rank-math'),
    'variable' => 'custom_page',
    'example' => custom_page_call_back(),
    ],
    'custom_page_call_back'
    );
    });

    function custom_page_call_back() {
    if (is_paged()) {
    global $wp_query;

    $current = max(1, get_query_var('paged'));
    $total = max(1, $wp_query->max_num_pages);

    return sprintf(
    esc_html__('Page %1$s of %2$s', 'rank-math'),
    $current,
    $total
    );
    }

    return '';
    }

    Once added, you can replace %page% with %custom_page% in your title or description settings.

    You may refer to this guide for adding custom code to your site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how that goes.

    Plugin Support Rakibuzzaman Siam

    (@rakibuzzamansiam1)

    Hello @porshegt9,
     
    Since we have not heard back from you, we are going to close this thread for now. If you still need any assistance, please feel free to reopen this thread or create a new one, and we will be happy to help.
     
    Thank you.

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

You must be logged in to reply to this topic.