Display short form of Months instead of long form (Jan and not January)

#42695
  • Resolved withxps
    Rank Math free

    Hi,

    I switched from Yoast SEO to Rank Math in the hope that my problems will be solved here.

    I am loving it. It got huge features.

    But, I would like to raise an issue here:

    For SEO purposes, in Title Tag, I am want to insert a Short Form of month instead of long-form using shortcodes.

    For Ex.,

    I want to display Jan instead of January. Sept instead of September.

    I read from here https://wordpress.org/support/article/formatting-date-and-time/ that “M” will do this.

    I got no knowledge of how this all works and how to make it possible myself.

    Link to screenshot to explain further – https://prnt.sc/ryb9ir

    I expect to hear from you.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael Davis
    Rank Math pro

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    You can easily register a new custom variable name called %current_month_M% to use on your posts by adding the following code to your theme’s functions.php file:

    /**
     * A custom replacement variable to get the current month in custom format
     */
    
    add_action( 'rank_math/vars/register_extra_replacements', function(){
     rank_math_register_var_replacement(
     'current_month_M',
     [
     'name'        => esc_html__( 'Current month', 'rank-math' ),
     'description' => esc_html__( 'Current server time displaying month in custom format', 'rank-math' ),
     'variable'    => 'current_month_M',
     'example'     => custom_date_callback(),
     ],
     'custom_date_callback()'
     );
    });
    
    function custom_date_callback(){
    	
    	return date_i18n( 'M' );
    	
    }

    Looking forward to helping you. Thank you.

    ​​​​​​​

    withxps
    Rank Math free

    Hi,

    First, will %currentmonth% still work or do I need to use another code. As the matter of the fact, I have added %currentmonth% already in all post title tags. So, tell me if I need to replace this with some new code?

    Second, as you suggested in this thread https://support.rankmath.com/reply/12120/, you gave two sets of codes. But, in my case, you suggested to insert only one code. Or, do I need to insert another code to override the old one?

    Third, I think this is not working as of now, As April should show as APR but it is still showing as April.

    Please let me know.

    Michael Davis
    Rank Math pro

    Hello,

    Thank you for contacting Rank Math today.

    I am sorry if I wasn’t clear in the last response, once you have added this code to your theme’s functions.php you will need to use the replacement variable : %current_month_M% instead of the one you were using to display the short form.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Display short form of Months instead of long form (Jan and not January)’ is closed to new replies.