• Resolved mansour

    (@iransound)


    Hi,

    When using the %page% variable in Rank Math templates, I noticed that Rank Math automatically adds a dash (-) before the pagination text.

    This behavior makes sense for the SEO title, but when using %page% in the meta description template, the dash is still added and it doesn’t look correct in the description.

    Example output in meta description:

    <title>Example - Fastest Site - Page 2 of 10</title>
    <meta name="description" content="Add SEO meta and OpenGraph details to your homepage. - Page 2 of 10"/>

    Is there a way to remove or control this dash when the %page% variable is used in the meta description?

    Thanks.

    • This topic was modified 1 week ago by mansour.
Viewing 1 replies (of 1 total)
  • Plugin Support Jaideep Asrani

    (@jaideeprm)

    Hello @iransound,

    Thank you for contacting Rank Math support.

    It isn’t possible to change the output of the %page% variable. However, you can use the following filter to create a custom variable that doesn’t include the separator:

    add_action( 'rank_math/vars/register_extra_replacements', function() {
    	rank_math_register_var_replacement(
    		'paged',
    		[
    			'name'        => esc_html__( 'Page Number', 'rank-math' ),
    			'description' => esc_html__( 'Current page and total pages', 'rank-math' ),
    			'variable'    => 'paged',
    			'example'     => paged_callback(),
    		],
    		'paged_callback'
    	);
    } );
    
    function paged_callback() {
    	global $wp_query;
    
    	$current_page = max( 1, get_query_var( 'paged' ) );
    	$total_pages  = max( 1, $wp_query->max_num_pages );
    
    	return sprintf( 'Page %d of %d', $current_page, $total_pages );
    }

    Here is how to add a filter to your site: https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Once done, you can use the %paged% variable in the meta description.

    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.