Clicky

  1. Home
  2. How To
  3. How to Modify Date or Change Date Format in AMP

How to Modify Date or Change Date Format in AMP

In this tutorial we will show you two ways to Modify or Change Date Format in AMP

1 – By using an Option in AMP settings

2 – By using Code

1 – By using an Option in AMP settings

  • You will find this option in this WordPress Dashboard -> Navigate to AMP option Panel -> Date -> In this “Show Date As” option you need to select the “Modified Date” option.
  • Date Format: Once you select “Date Format” option two options will be displayed “Ago” and “Traditional view” as per your requirement you can enable those options and then click on the “Save Changes” button.

Ago:

  • Ago: In Date format, Select the Date Format of Posts.
  • Text for the Date Format: In this file, you need to enter Date Format for example – English – % days ago, Spain – ago % days

Traditional view :

  • Traditional view: In Date format select the Date Format of Posts
  • Time: By using this option you can Enable or Disable Time In Posts
  • How to Change Date and Time Format in WordPress for this follow this tutorial Click Here.

The Output Of Modify Date in AMP

2 – By using Code

A) – Modifying via Filter

  • You need to add the following filter code into your theme’s functions.php file at the end of the code or create a custom plugin and add the following code.
add_filter('ampforwp_modify_post_date','ampforwp_modify_date_index');
function ampforwp_modify_date_index($date) {
    $date = get_the_date();    
    return $date;
}
  • By doing the above-mentioned changes you’ve changed the date format, or you can get the desired format by playing with the ampforwp_modify_date_index() function code.

B) – Using amp_date() function

  • If you have created a custom template and used the function amp_date() and want to change the date, then you can pass an array like shown below.

Example:

amp_date(array('custom_format'=>'l - d, F, Y') );
  • We use Date() function to show the date and all the compatible date formats are supported by amp_date() function. Here is the list of all the available date types here.

The Output of the Using amp_date() function

How to change date in amp wordpress

That’s it for this tutorial!

We hope it helped you. If you have any feedback or questions, then please share them in the comments section below.

Ask your Questions Directly!
If you can't find the solutions in this article, then just ask us in the comments and we will answer it for you!
Updated on July 14, 2020

    Are you still looking for a solution?

    Then fill out the below form and we will reach out to you within a few hours.

    Was this article helpful?

    Related Articles

    Comments

    1. I do not want to show sate on homepage in the free version in the third design template. I want to completely remove date. The single posts dont show date in meta but the homepage shows like 1 year ago, 11 months ago. Please guide me how to remove it.

    2. Hi there,

      I have inserted this code into functions.php but for Design 1 it still shows human readable time. I looked into the code for design 1 and it seems hardcoded. Is there any way around this? Thanks!

    Leave a Comment