🛍 Cyber Monday Sale: 35% DISCOUNT + 2x Benefits + $15K+ Offers!

LEARN MORE!

Support Rank Math Free variable %currentmonth% custom Reply To: variable %currentmonth% custom

Reply To: variable %currentmonth% custom

Hello,

Thank you for contacting Rank Math today and sorry for the delay.

1). You can work around this issue by registering a custom replacement variable that will output only the month number. Here is some code that you can add to your theme’s functions.php file to achieve this:

add_action( 'rank_math/vars/register_extra_replacements', 'register_custom_rep' );
function register_custom_rep() {
		RankMath\Helper::register_var_replacement(
			'current_month_custom','get_current_month_custom',
			array(
				'name'    => esc_html__( 'Current Month', 'rank-math' ),
				'desc'    => esc_html__( 'Current server month', 'rank-math' ),
				'example' => current_time( 'F' ),
			)
		);}
	function get_current_month_custom() {
                if ( ! isset( $replacement ) ) {
			$replacement = date('n');
		}

		return $replacement;
	}

You will then need to replace the usage of %current_month% with %current_month_custom%

2). This suggests that some variables were not successfully migrated to Rank Math. You can fix this by adding the following code to your theme’s functions.php file to replace the variables with their values.

/**
 * Override the current Rank Math headline and description on arcticle snippet
 * 
 * @param array $entity Snippet Data
 * @return array
 */
add_filter( "rank_math/snippet/rich_snippet_article_entity", function( $entity ) {
	global $post;
	$entity['headline'] = get_the_title();
	$entity['description'] = wp_html_excerpt(strip_shortcodes( $post->post_content ), 155 );
	return $entity;
});

Looking forward to helping you. Thank you.

​​​​​​