{"id":1403,"date":"2018-10-03T19:31:52","date_gmt":"2018-10-03T17:31:52","guid":{"rendered":"https:\/\/felix-arntz.me\/?p=1403"},"modified":"2025-02-11T08:12:23","modified_gmt":"2025-02-11T16:12:23","slug":"using-amp-timeago-relative-dates-native-amp-site","status":"publish","type":"post","link":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/","title":{"rendered":"Using amp-timeago to display relative dates on your Native-AMP site"},"content":{"rendered":"\n<p>In my <a href=\"https:\/\/felix-arntz.me\/blog\/site-is-now-gutenberg-and-amp\/\">post about how I renewed my website with Gutenberg and native AMP support<\/a> I mentioned that I&#8217;d be sharing some implementation details. A couple days ago I posted about <a href=\"https:\/\/felix-arntz.me\/blog\/building-a-reusable-gutenberg-section-block\/\">how I built a reusable section block with Gutenberg<\/a>. Today we&#8217;re going to look at an AMP-specific feature and how I made use of it for my site. While the <a href=\"https:\/\/github.com\/Automattic\/amp-wp\">AMP plugin for WordPress<\/a> does a great job in ensuring your WordPress site becomes AMP-compatible, there are still tons of additional AMP features to explore, some of which are too specific to generally add support in the plugin. An example of this is the <a href=\"https:\/\/www.ampproject.org\/docs\/reference\/components\/amp-timeago\"><code>amp-timeago<\/code> component<\/a>, which allows displaying relative time periods, pretty much in realtime. In other words, instead of showing a concrete date and time, it will show a string such as <em>&#8220;x seconds\/minutes\/hours\/days\/weeks\/months\/&#8230; ago&#8221;<\/em> &#8211; you get the gist. You can see a live-example of this when looking at when this post was published, just above, below the headline. And this is precisely what we&#8217;re going to focus on in this post, how I implemented this feature and how you can implement it for your Native-AMP WordPress site.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Why use <code>amp-timeago<\/code>?<\/h2>\n\n\n\n<p>The <code>amp-timeago<\/code> component of AMP allows to display relative time periods between now and another given date and time. This has become a common practice in a lot of platforms such as Facebook or Twitter, so why not leverage it on your blog as well?<\/p>\n\n\n\n<p>In WordPress, there is a <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/human_time_diff\/\"><code>human_time_diff()<\/code> function<\/a> that allows you to do something similar. However, since that function operates server-side, it is practically unusable for real-world sites, since it only shows accurate time periods if you don&#8217;t use any kind of page caching and let WordPress handle every request directly &#8211; which I don&#8217;t recommend for performance reasons.<\/p>\n\n\n\n<p><code>amp-timeago<\/code> is a client-side solution. On the server, you only provide the date and time in a machine-readable format, and also a regular formatted date\/time value that is human-readable. The latter will not be visible on the page because a relative time period will be displayed instead. <code>amp-timeago<\/code> will however display it if you hover over the time period, which is another benefit over the simple <code>human_time_diff()<\/code>. If a user wants to quickly find out the exact date, they still can.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Displaying relative post dates<\/h2>\n\n\n\n<p>Themes typically handle output of the post dates through either a function (such as <code>mytheme_posted_on()<\/code>) or a dedicated template (such as <code>template-parts\/entry-date.php<\/code>). I personally prefer using templates for generating markup, so that&#8217;s what we&#8217;ll look it in this post. The code here is applicable to the function approach as well though.<\/p>\n\n\n\n<p>Post dates are commonly displayed inside <code>time<\/code> elements &#8211; so the most important part here is that we need to use <code>amp-timeago<\/code> elements instead. However, since AMP support is typically enabled through the plugin, we wanna make sure we fall back gracefully, in case the plugin is not activated. This allows using the theme also for sites that do not support native AMP. Let&#8217;s have a look at the code I used to render post dates.<\/p>\n\n\n<pre class=\"alignwide\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">$post_date_gmt       = get_post_time( <span class=\"hljs-string\">'c'<\/span>, <span class=\"hljs-literal\">true<\/span>, <span class=\"hljs-literal\">null<\/span>, <span class=\"hljs-literal\">false<\/span> );\n$post_date_formatted = get_date_from_gmt( $post_date_gmt, get_option( <span class=\"hljs-string\">'date_format'<\/span> ) );\n\n<span class=\"hljs-keyword\">if<\/span> ( felix_arntz_v6_is_amp() ) {\n\t<span class=\"hljs-comment\">\/* translators: %s: post time period *\/<\/span>\n\t$posted      = _x( <span class=\"hljs-string\">'Posted %s'<\/span>, <span class=\"hljs-string\">'post date'<\/span>, <span class=\"hljs-string\">'felix-arntz-v6'<\/span> );\n\t$locale      = substr( get_locale(), <span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">2<\/span> );\n\t$time_string = <span class=\"hljs-string\">'&lt;amp-timeago height=\"24\" layout=\"fixed-height\" datetime=\"%1$s\" locale=\"'<\/span> . esc_attr( $locale ) . <span class=\"hljs-string\">'\"&gt;%2$s&lt;\/amp-timeago&gt;'<\/span>;\n} <span class=\"hljs-keyword\">else<\/span> {\n\t<span class=\"hljs-comment\">\/* translators: %s: post date *\/<\/span>\n\t$posted      = _x( <span class=\"hljs-string\">'Posted on %s'<\/span>, <span class=\"hljs-string\">'post date'<\/span>, <span class=\"hljs-string\">'felix-arntz-v6'<\/span> );\n\t$time_string = <span class=\"hljs-string\">'&lt;time class=\"entry-date\" datetime=\"%1$s\"&gt;%2$s&lt;\/time&gt;'<\/span>;\n}\n\n$time_string = sprintf(\n\t$time_string,\n\tesc_attr( $post_date_gmt ),\n\tesc_html( $post_date_formatted )\n);\n\n?&gt;\n<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">span<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"posted-on\"<\/span>&gt;<\/span>\n\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\tprintf(\n\t\tesc_html( $posted ),\n\t\t<span class=\"hljs-string\">'&lt;a href=\"'<\/span> . esc_url( get_permalink() ) . <span class=\"hljs-string\">'\" rel=\"bookmark\"&gt;'<\/span> . $time_string . <span class=\"hljs-string\">'&lt;\/a&gt;'<\/span> <span class=\"hljs-comment\">\/\/ phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped<\/span>\n\t);\n\t<span class=\"hljs-meta\">?&gt;<\/span><\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">span<\/span>&gt;<\/span><\/span>\n&lt;?php<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>First of all, as you can see, I use the GMT time the post was published at. This doesn&#8217;t have to do anything with AMP, I just strongly recommend following this pattern for any moment you are rendering dates. When a site changes their timezone, all dates from old posts will become invalid then &#8211; the GMT dates do not though. So relying on GMT will ensure your dates are always accurate, and you can still display them in the local time (which is what <code>get_date_from_gmt()<\/code> is used for). If you are interested in more background on this, please watch <a href=\"https:\/\/wordpress.tv\/2018\/05\/06\/andrey-savchenko-wordpress-breaks-time-and-how-to-fix-it\/\">the amazing WordCamp session by Rarst about broken time<\/a>.<\/p>\n\n\n\n<p>Then, there is a function <code>felix_arntz_v6_is_amp()<\/code>. This is a simple wrapper function for checking whether we should serve AMP content for the current request. I recommend you to add a similar function to your theme. Here is its simple code:<\/p>\n\n\n<pre aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\">\/**\n * Checks whether the current context is an AMP endpoint.\n *\n * <span class=\"hljs-doctag\">@since<\/span> 1.0.0\n *\n * <span class=\"hljs-doctag\">@return<\/span> bool True if an AMP endpoint, false otherwise.\n *\/<\/span>\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">felix_arntz_v6_is_amp<\/span><span class=\"hljs-params\">()<\/span> <\/span>{\n\t<span class=\"hljs-keyword\">return<\/span> function_exists( <span class=\"hljs-string\">'is_amp_endpoint'<\/span> ) &amp;&amp; is_amp_endpoint();\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Depending on whether AMP should be served or not, we then decide on which tag to render, and also which text to use in combination with it. &#8220;Posted on August 4th, 2018&#8221; sounds correct, but &#8220;Posted on 2 months ago&#8221; doesn&#8217;t, right? Therefore, when rendering a relative time period via <code>amp-timeago<\/code>, we need to adjust the related string to get the proper &#8220;Posted 2 months ago&#8221; output. The only additional tweaks we need for <code>amp-timeago<\/code> is providing our site&#8217;s language to it, which we can detect via <code>get_locale()<\/code>, and provide a <code>height<\/code> attribute to it. I chose 24 because that fits well with the font size and line height on my site.<\/p>\n\n\n\n<p>Note that the <code>datetime<\/code> attribute of both the <code>time<\/code> and <code>amp-timeago<\/code> tags requires a date in\u00a0ISO 8601 format, with timezone information. To get this in a way that we can a 100% rely on, we need to use the GMT date &#8211; as indicated before, for other timezones things can get clunky here for multiple reasons.<\/p>\n\n\n\n<p>And that is already it &#8211; you can now render your post dates as related time periods via the\u00a0<code>amp-timeago<\/code> component.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Displaying relative comment dates<\/h3>\n\n\n\n<p>Just as an extra addition, I&#8217;ll share the code to accomplish this for comment dates as well. You might have a dedicated template for a single comment in your theme where you could use that. Here is the code responsible for rendering the current comment date with <code>amp-timeago<\/code> support:<\/p>\n\n\n<pre class=\"alignwide\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">$comment_date_gmt       = get_comment_time( <span class=\"hljs-string\">'c'<\/span>, <span class=\"hljs-literal\">true<\/span>, <span class=\"hljs-literal\">false<\/span> );\n$comment_date_formatted = sprintf(\n\t<span class=\"hljs-comment\">\/* translators: 1: comment date, 2: comment time *\/<\/span>\n\t__( <span class=\"hljs-string\">'%1$s at %2$s'<\/span>, <span class=\"hljs-string\">'felix-arntz-v6'<\/span> ),\n\tget_date_from_gmt( $comment_date_gmt, get_option( <span class=\"hljs-string\">'date_format'<\/span> ) ),\n\tget_date_from_gmt( $comment_date_gmt, get_option( <span class=\"hljs-string\">'time_format'<\/span> ) )\n);\n\n<span class=\"hljs-keyword\">if<\/span> ( felix_arntz_v6_is_amp() ) {\n\t$locale      = substr( get_locale(), <span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">2<\/span> );\n\t$time_string = <span class=\"hljs-string\">'&lt;amp-timeago height=\"24\" layout=\"fixed-height\" datetime=\"%1$s\" locale=\"'<\/span> . esc_attr( $locale ) . <span class=\"hljs-string\">'\"&gt;%2$s&lt;\/amp-timeago&gt;'<\/span>;\n} <span class=\"hljs-keyword\">else<\/span> {\n\t$time_string = <span class=\"hljs-string\">'&lt;time datetime=\"%1$s\"&gt;%2$s&lt;\/time&gt;'<\/span>;\n}\n\n$time_string = sprintf(\n\t$time_string,\n\tesc_attr( $comment_date_gmt ),\n\tesc_html( $comment_date_formatted )\n);\n\n?&gt;\n<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"comment-date\"<\/span>&gt;<\/span>\n\t<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">a<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"&lt;?php echo esc_url( get_comment_link() ); ?&gt;\"<\/span>&gt;<\/span>\n\t\t<span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span> <span class=\"hljs-keyword\">echo<\/span> $time_string; <span class=\"hljs-comment\">\/* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped *\/<\/span> <span class=\"hljs-meta\">?&gt;<\/span><\/span>\n\t<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">a<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span><\/span>\n&lt;?php<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Note that the markup is a bit different, but that is just because I personally render comment dates differently than post dates. They also don&#8217;t have the &#8220;Posted on&#8230;&#8221; \/ &#8220;Posted&#8230;&#8221; prefix. Otherwise, the code is fairly similar, with the exception that comment templating functions are used instead of the post templating functions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my post about how I renewed my website with Gutenberg and native AMP support I mentioned that I&#8217;d be sharing some implementation details. A couple days ago I posted about how I built a reusable section block with Gutenberg. Today we&#8217;re going to look at an AMP-specific feature and how I made use of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1412,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[71,97],"tags":[],"class_list":["post-1403","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using amp-timeago for relative dates in WordPress - felix-arntz.me<\/title>\n<meta name=\"description\" content=\"In this post I will explain how you can use the amp-timeago component to render relative time periods on your Native-AMP WordPress site.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using amp-timeago for relative dates in WordPress - felix-arntz.me\" \/>\n<meta property=\"og:description\" content=\"In this post I will explain how you can use the amp-timeago component to render relative time periods on your Native-AMP WordPress site.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/\" \/>\n<meta property=\"og:site_name\" content=\"felix-arntz.me\" \/>\n<meta property=\"article:published_time\" content=\"2018-10-03T17:31:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-11T16:12:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Felix\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@felixarntz\" \/>\n<meta name=\"twitter:site\" content=\"@felixarntz\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Felix\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/\"},\"author\":{\"name\":\"Felix\",\"@id\":\"https:\/\/felix-arntz.me\/#\/schema\/person\/c7c3c658d2e59bbddf3e8684a6846e55\"},\"headline\":\"Using amp-timeago to display relative dates on your Native-AMP site\",\"datePublished\":\"2018-10-03T17:31:52+00:00\",\"dateModified\":\"2025-02-11T16:12:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/\"},\"wordCount\":955,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/felix-arntz.me\/#\/schema\/person\/c7c3c658d2e59bbddf3e8684a6846e55\"},\"image\":{\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg\",\"articleSection\":[\"Tutorials\",\"WordPress\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/\",\"url\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/\",\"name\":\"Using amp-timeago for relative dates in WordPress - felix-arntz.me\",\"isPartOf\":{\"@id\":\"https:\/\/felix-arntz.me\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg\",\"datePublished\":\"2018-10-03T17:31:52+00:00\",\"dateModified\":\"2025-02-11T16:12:23+00:00\",\"description\":\"In this post I will explain how you can use the amp-timeago component to render relative time periods on your Native-AMP WordPress site.\",\"breadcrumb\":{\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#primaryimage\",\"url\":\"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg\",\"contentUrl\":\"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg\",\"width\":1200,\"height\":675,\"caption\":\"Using amp-timeago for relative dates\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/felix-arntz.me\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tutorials\",\"item\":\"https:\/\/felix-arntz.me\/blog\/category\/tutorials\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using amp-timeago to display relative dates on your Native-AMP site\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/felix-arntz.me\/#website\",\"url\":\"https:\/\/felix-arntz.me\/\",\"name\":\"felix-arntz.me\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/felix-arntz.me\/#\/schema\/person\/c7c3c658d2e59bbddf3e8684a6846e55\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/felix-arntz.me\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/felix-arntz.me\/#\/schema\/person\/c7c3c658d2e59bbddf3e8684a6846e55\",\"name\":\"Felix\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/felix-arntz.me\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/09\/felix-arntz-site-icon.png\",\"contentUrl\":\"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/09\/felix-arntz-site-icon.png\",\"width\":512,\"height\":512,\"caption\":\"Felix\"},\"logo\":{\"@id\":\"https:\/\/felix-arntz.me\/#\/schema\/person\/image\/\"},\"description\":\"Developer Programs Engineer at Google. WordPress Core Committer. Previously Yoast. Runner, musician, movie geek. Aprendiendo espa\u00f1ol. Fueled by Mountain Dew.\",\"sameAs\":[\"https:\/\/x.com\/felixarntz\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using amp-timeago for relative dates in WordPress - felix-arntz.me","description":"In this post I will explain how you can use the amp-timeago component to render relative time periods on your Native-AMP WordPress site.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/","og_locale":"en_US","og_type":"article","og_title":"Using amp-timeago for relative dates in WordPress - felix-arntz.me","og_description":"In this post I will explain how you can use the amp-timeago component to render relative time periods on your Native-AMP WordPress site.","og_url":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/","og_site_name":"felix-arntz.me","article_published_time":"2018-10-03T17:31:52+00:00","article_modified_time":"2025-02-11T16:12:23+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg","type":"image\/jpeg"}],"author":"Felix","twitter_card":"summary_large_image","twitter_creator":"@felixarntz","twitter_site":"@felixarntz","twitter_misc":{"Written by":"Felix","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#article","isPartOf":{"@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/"},"author":{"name":"Felix","@id":"https:\/\/felix-arntz.me\/#\/schema\/person\/c7c3c658d2e59bbddf3e8684a6846e55"},"headline":"Using amp-timeago to display relative dates on your Native-AMP site","datePublished":"2018-10-03T17:31:52+00:00","dateModified":"2025-02-11T16:12:23+00:00","mainEntityOfPage":{"@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/"},"wordCount":955,"commentCount":0,"publisher":{"@id":"https:\/\/felix-arntz.me\/#\/schema\/person\/c7c3c658d2e59bbddf3e8684a6846e55"},"image":{"@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#primaryimage"},"thumbnailUrl":"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg","articleSection":["Tutorials","WordPress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/","url":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/","name":"Using amp-timeago for relative dates in WordPress - felix-arntz.me","isPartOf":{"@id":"https:\/\/felix-arntz.me\/#website"},"primaryImageOfPage":{"@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#primaryimage"},"image":{"@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#primaryimage"},"thumbnailUrl":"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg","datePublished":"2018-10-03T17:31:52+00:00","dateModified":"2025-02-11T16:12:23+00:00","description":"In this post I will explain how you can use the amp-timeago component to render relative time periods on your Native-AMP WordPress site.","breadcrumb":{"@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#primaryimage","url":"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg","contentUrl":"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg","width":1200,"height":675,"caption":"Using amp-timeago for relative dates"},{"@type":"BreadcrumbList","@id":"https:\/\/felix-arntz.me\/blog\/using-amp-timeago-relative-dates-native-amp-site\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/felix-arntz.me\/"},{"@type":"ListItem","position":2,"name":"Tutorials","item":"https:\/\/felix-arntz.me\/blog\/category\/tutorials\/"},{"@type":"ListItem","position":3,"name":"Using amp-timeago to display relative dates on your Native-AMP site"}]},{"@type":"WebSite","@id":"https:\/\/felix-arntz.me\/#website","url":"https:\/\/felix-arntz.me\/","name":"felix-arntz.me","description":"","publisher":{"@id":"https:\/\/felix-arntz.me\/#\/schema\/person\/c7c3c658d2e59bbddf3e8684a6846e55"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/felix-arntz.me\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/felix-arntz.me\/#\/schema\/person\/c7c3c658d2e59bbddf3e8684a6846e55","name":"Felix","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/felix-arntz.me\/#\/schema\/person\/image\/","url":"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/09\/felix-arntz-site-icon.png","contentUrl":"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/09\/felix-arntz-site-icon.png","width":512,"height":512,"caption":"Felix"},"logo":{"@id":"https:\/\/felix-arntz.me\/#\/schema\/person\/image\/"},"description":"Developer Programs Engineer at Google. WordPress Core Committer. Previously Yoast. Runner, musician, movie geek. Aprendiendo espa\u00f1ol. Fueled by Mountain Dew.","sameAs":["https:\/\/x.com\/felixarntz"]}]}},"jetpack_featured_media_url":"https:\/\/felix-arntz.me\/wp-content\/uploads\/2018\/10\/using-amp-timeago-for-relative-dates.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/posts\/1403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/comments?post=1403"}],"version-history":[{"count":10,"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/posts\/1403\/revisions"}],"predecessor-version":[{"id":1420,"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/posts\/1403\/revisions\/1420"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/media\/1412"}],"wp:attachment":[{"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/media?parent=1403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/categories?post=1403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/felix-arntz.me\/api\/wp\/v2\/tags?post=1403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}