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

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.

Share
Published by
Ahmed Kaludi

How to create an AWeber form in AMP

If you want to add an AWeber form in AMP then first you need to…

3 years ago

How to setup webpushr notification in AMP

Webpushr is the fastest growing web push notifications platform that marketers love & developers rely…

3 years ago

How to add Adobe Analytics in AMP

Follow these steps to add Adobe Analytics in AMP Step 1: Go to WordPress Admin Area -> AMP…

3 years ago

What is the CWV plugin all about

Core Web Vitals are the subset of Web Vitals that apply to all web pages,…

4 years ago

How to fix “Alternate page with proper canonical tag” Page Index issue in Google Search Console

The following reasons can be shown for non-indexing. Server error (5xx) Your server returned a 500-level…

4 years ago

Google Analytics ( GA4 ) integration in AMPforWP

We have added the Google Analytics 4 ( GA 4 ) integration in AMPforWP v1.0.80.…

4 years ago