How can i Show Modified Date as ISO 8601 format on Post Title

#208363
  • Resolved Anonymous
    Rank Math free

    Currently, I saw that I am not able to Add the Modified Date in ISO 8601 format
    Like if I want to add this date (let post Modified Date is 07/JUNE/2021) and it shows me like:”June 7, 2021″ but I want to show it in IOS 8601 Format like ” 2021-06-07T00:00:00″
    but I am not able to do this

Viewing 3 replies - 1 through 3 (of 3 total)
  • Brian
    Rank Math free

    Hello,

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

    Could you please clarify where you want to add/change this date format is it precisely on the Rank Math’s SEO title or on the actual WP Post title?

    For Rank Math’s SEO title, you will have to create a custom variable that you can use in the SEO meta snippet section. To achieve this please insert this code in your theme’s functions.php file:

     add_action( 'rank_math/vars/register_extra_replacements', function(){
     rank_math_register_var_replacement(
     'current_date_M',
     [
     'name'        => esc_html__( 'Current month', 'rank-math' ),
     'description' => esc_html__( 'Current server time displaying month in custom format', 'rank-math' ),
     'variable'    => 'current_date_M',
     'example'     => custom_date_callback(),
     ],
     'custom_date_callback()'
     );
    });
    
    function custom_date_callback(){
    	
    	return date_i18n( 'Y/m/d \a\t g:ia' );
    	
    }

    For this code, we have created the custom variable as %current_date_M% which is what you need to insert in the Meta snippet of the post you wish to include the date.

    Hope this is helpful. We really look forward to helping you more.

    Thank you.

    Anonymous
    Rank Math free

    Thanks for Your Reply, But
    I want it for Post Update Date and Time in IOS 8601 format Like
    ‘ 2021-06-07T13:04:00+05:30 ‘ to be return in frontent
    not like ‘2021/06/07 at 6:10pm’

    Hello,

    Thank you for keeping in touch with us.

    In this case, you may insert this line in the call back function of the filter my colleague provided:

    return date_format(new DateTime(get_the_modified_time()), 'c');

    If you wish to only get the modified date of the post, you can use this instead:

    return date_format(new DateTime(get_the_modified_date()), 'c');

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

    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 ‘How can i Show Modified Date as ISO 8601 format on Post Title’ is closed to new replies.