WordPressで投稿の最終更新日を表示したいですか?
定期的に投稿を更新しているサイトもあります。各投稿がいつ更新されたかを表示することで、読者はコンテンツを見逃すことなく、信頼を築き、SEOランキングを上げる権威を築くことができます。
この投稿では、WordPressで投稿の最終更新日を表示する方法を紹介する。
なぜWordPressで投稿の最終更新日を表示するのか?
訪問者がWordPressブログの投稿やページを表示すると、WordPressテーマは投稿が公開された日付を表示します。これは、ほとんどのブログや静的サイトでは問題ありません。
しかし、WordPressは、古い投稿が定期的に更新されるサイトでも使われている。このような出版物では、投稿が最後に更新された日時を表示することが重要です。
例えば、WPBeginnerでは、チュートリアルを定期的に更新し、各投稿に「最終更新日」を表示しています。もし公開した日付だけを表示していたら、読者は情報が古いと判断して投稿を飛ばしてしまうでしょう。
もうひとつの例はニュースサイトだ。彼らはしばしば古い記事を更新し、新しい開発者を表示したり、訂正を加えたり、メディアファイルを挿入したりする。もし公開した日付しか表示しなければ、ユーザーはそれらの更新を見逃すことになる。
さらに、Googleをはじめとする検索エンジンは、最新の情報を上位に表示したがります。更新日を表示することで、Googlebotなどが投稿が最後に触れられたのがいつかを知ることができます。
それでは、WordPressで投稿の最終更新日を簡単に表示する方法を見ていきましょう。
動画チュートリアル
書面によるチュートリアルをご希望の場合は、以下のガイドをお読みください。
カテゴリー:WordPressで投稿の最終更新日を表示する方法
このチュートリアルでは、WordPressファイルにコードを追加する必要があります。この作業を行ったことがない場合は、WordPressでコードをコピー&ペーストする方法をご覧ください。
方法1:投稿コンテンツの前に最終更新日を表示する
このチュートリアルでは、WordPressにカスタムコードを追加する最も安全で簡単な方法であるWPCodeを使用します。
サイトのコアWordPressファイルの編集は、小さなミスやタイプミスでもサイトを壊してしまう可能性があるため危険です。 そのため、WPCodeを使用してコードスニペットを追加することをお勧めします。
まず、無料のWPCodeプラグインをインストールし、有効化する必要があります。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。
プラグインを有効化したら、WordPressダッシュボードのCode Snippets ” Add Snippetに移動します。Last updated date」を検索し、「Display the Last Updated Date」というタイトルの結果にマウスオーバーします。
このコードでは、投稿の公開日と最終更新日が異なるかどうかをチェックします。もし違っていれば、投稿コンテンツの前に最終更新日を表示します。(これはWPBeginnerでのやり方です)。
次に、「スニペットを使う」ボタンをクリックします。
次に、「Edit Snippet」画面が表示されます。WPCodeはすでにあなたのためにスニペットを設定しています。
スイッチを「有効化」に切り替え、準備ができたら「更新」をクリックするだけだ。
このコード・スニペットはサイトのボディ・テキスト・スタイルを使って更新日時を表示するので、カスタムCSSを追加して最終更新日時の外観を整えることができます。以下は、手始めに使えるちょっとしたCSSスニペットです:
.last-updated {
font-size: small;
text-transform: uppercase;
background-color: #fffdd4;
}
WordPressのデモサイトではこのように表示されます。
さらに、もしあなたが上級ユーザーで、そうすることに抵抗がなければ、テーマのfunctions.phpファイルに以下を追加することができる。
FTPまたはWordPressホスティングサービスのファイルマネージャーからサイトに接続し、サイトの/wp-content/themes/yourthemename/フォルダー内のファイルを見つけるだけです。
$u_time = get_the_time( 'U' );
$u_modified_time = get_the_modified_time( 'U' );
// Only display modified date if 24hrs have passed since the post was published.
if ( $u_modified_time >= $u_time + 86400 ) {
$updated_date = get_the_modified_time( 'F jS, Y' );
$updated_time = get_the_modified_time( 'h:i a' );
$updated = '<p class="last-updated">';
$updated .= sprintf(
// Translators: Placeholders get replaced with the date and time when the post was modified.
esc_html__( 'Last updated on %1$s at %2$s' ),
$updated_date,
$updated_time
);
$updated .= '</p>';
echo wp_kses_post( $updated );
}
方法2:テーマテンプレートに最終更新日を追加する
また、公開する日付の代わりに更新日を表示することも、そのすぐ下に表示することもできます。
この方法では、特定のWordPressテーマファイルを編集する必要があります。編集するファイルは、使用しているテーマによって異なります。
多くのWordPressテーマは、投稿日時などのメタデータを表示するために独自のテンプレートタグを使用しています。よりシンプルなテーマでは、コンテンツやメタ情報を表示するために、single.php
、archive.php
、その他のテンプレートファイルを使用します。
日付と時刻を表示するレスポンシブ・コードが含まれているファイルを探す必要があります。そのコードを以下のコードに置き換えるか、テーマの日付と時刻のコードの直後に追加してください。
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
echo "<p>Last modified on ";
the_modified_time('F jS, Y');
echo " at ";
the_modified_time();
echo "</p> "; }
投稿が更新された時刻を表示したくない場合は、6行目と7行目を削除することができます。
デモサイトではこのように表示されました。Twenty Twenty-Oneテーマでは、コードスニペットをinc
フォルダー内のtemplate-tags.php
ファイルに追加しました。
カテゴリー:WordPressで投稿の最終更新日を管理する方法
各投稿の最終更新日が追加され、投稿に変更を加えるたびに自動的に更新されるようになりました。しかし、スペルミスの修正やタグの追加など、完全な更新ではなく、ちょっとした修正にとどめる場合はどうでしょうか?
小さな変更であれば、SEOの観点から更新日は変更しない方がよいでしょう。読者には、投稿に最後に大きな更新が行われた日付が表示されます。
更新日時を変更せずに投稿を更新できるプラグインをいくつか紹介しよう。
方法1:Limit Modified Dateプラグインを使う
まず、Limit Modified Dateプラグインをインストールして有効化する必要があります。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。
注:このプラグインは最近更新されていません。しかし、WordPressの最新バージョンでテストしたところ、まだ動作していました。
有効化した場合、投稿の編集時に新しいチェックボックスが表示されます。これは「更新日時を更新しない」と表示されています。
投稿のマイナー更新を行う際、このボックスにチェックを入れるだけで、更新日時は変更されません。
方法2:AIOSEOプラグインを使う(推奨)
AIOSEOは、All In One SEOとしても知られており、市場で最高のWordPress SEOプラグインです。複雑な専門用語を学ぶことなく検索順位を向上させることができるので、サイトのトラフィックを増やすことができます。
さらに詳しくは、All In One SEO for WordPressを正しく設定する方法をご覧ください。
すでにAIOSEOを使って検索エンジンのランキングを向上させているのであれば、投稿の更新日の管理にもAIOSEOを使うことができる。
有効化した場合、投稿の編集時に「更新日時を更新しない」という新しいチェックボックスが表示されます。投稿にちょっとした変更を加える際に、このチェックボックスをオンにすることができます。
誤字や単純なミスを修正する場合に便利で、読者や検索エンジンに知らせたい変更を加える場合は、このボックスのチェックを外すことができます。
このチュートリアルで、WordPressで投稿の最終更新日を表示する方法を学んでいただけたら幸いです。WordPressのパフォーマンスを高速化する方法や、ブログのトラフィックを増やすための実績のあるヒントのリストもご覧ください。
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Syed Balkhi
Hey WPBeginner readers,
Did you know you can win exciting prizes by commenting on WPBeginner?
Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
You can get more details about the contest from here.
Start sharing your thoughts below to stand a chance to win!
Daniel M.
Simply echo “the_modified_date()” where you want to show it in your theme files.
WPBeginner Support
That is better used within the WordPress loop if you want to use it, we recommend the second method in this guide if you wanted something similar.
管理者
Ajit Kumar
Hey, I am using WordPress Twenty Twenty-Three Theme I have used the above code which you provide in my Function.php Now the latest update date showing on all posts, I was waiting for Google crawling, and after Google crawled the data showed the Published date instead of Updated date.
How to get an Updated date on my Google Rich Snippet Please help I am very Thank full to you!
Thank You So Much!
WPBeginner Support
If you remove the published date from your posts that can help have Google show the updated date instead but there is not a guarantee of the date that Google will show as Google determines which one it decides to show.
管理者
Imran
I tried this but it shows both original published date and last updated date.
I want to show
if the post is update- show updated date
if not
just show original date.
How to do this.
WPBeginner Support
For what you’re wanting you would want to add an else statement that had your theme’s original option to display the date using the method to edit your theme template from this article. An example of what you would add is the code below:
else {
// Theme's code
}
管理者
Adam Baney
The code to insert into a theme file worked perfectly! I added it as a function in my functions.php file, and called it on the page. The allows me to update the code in 1 place, and it will update across my site, in case I want to show the last modified date for multiple post types or in custom templates. Thank you!
WPBeginner Support
Glad our guide was helpful!
管理者
MOHAMMED AQRABI
I have a question, for example, if I now display the date of the last update of the article and I have 800 articles and all the dates have changed for all articles at once, will this affect or harm the search engines
WPBeginner Support
It should not cause an issue, you would mainly need to give time for Google to recrawl your updated dates.
管理者
Raphael
Thank you so much for this tutorial!
I used the first method and it perfectly works for me but I am having one issue, the post is still showing the published date on google search instead of the latest update date.
How can I do away with this?
WPBeginner Support
It would depend on how recently it has changed, if you just added the updated date you would need to wait for Google to recrawl your post.
管理者
Masrafi
Hello, this was a very helpful blog and video. But when I apply, it shows the end of the content. please tell me the solution
WPBeginner Support
You may need to check with the support for your specific theme to check the placement of your code in case your theme has a different method for displaying the publish date.
管理者
Dean
s there a way to hide this on pages and only show on blog posts ? tx
WPBeginner Support
You would want to use the second method in this article for that
管理者
Gianluigi Filippelli
if ( get_post_type() ‘page’ ){
return $custom_content;
} else {
return $content;
}
Laura
Just a quick question, the updated date shows at the bottom of my posts, as opposed to the top.
Is there a solution to ensure the new updated date is at the beginning of the posts?
WPBeginner Support
It would depend on how your theme is designed. If you reach out to your theme’s support they should be able to help you place it in the correct location
管理者
Raman
Hi Team,
I am able to print updated date but it’s getting rendered below the featured image, can you advise how can print the udpated date on the top of the featured image, means right below the title.
WPBeginner Support
You would want to reach out to the support for your specific theme and they should be able to assist with that placement.
管理者
Sanaullah Farooq
Hello,
I want to show only post update date on page and in search results instead of publish date. How can I achieve that? I have tried everything.
WPBeginner Support
If you are unable to remove the published date then we would recommend reaching out to your specific theme’s support and they would be able to help you remove that.
管理者
Rachel Joan
OMG…
Thank you for saving my hours…
Thank you for this code.
You are the problem solver.
WPBeginner Support
Glad our guide was helpful
管理者
Danyl
Hi how about list of users who updated the post?
WPBeginner Support
You would want to take a look at your post revisions for that information
管理者
ali karimi
thanks a lot for your help
WPBeginner Support
You’re welcome
管理者
Ankit Sheoran
Last update is not showing in google what should i do but showing in my website
WPBeginner Support
If the change is recent, you would need to wait for Google’s cache to clear. Otherwise, you would want to check with your theme’s support to ensure they are not setting the specific publish date elsewhere
管理者
Shubham Davey
What if I want to show only the updated date & not the published date? The method shown here displays both published & updated date, I don’t want that, just updated date, that’s it.
WPBeginner Support
It would depend on your theme but you would use method 2 to replace the display of the last edited date. The location of that code varies from theme to theme.
管理者
Charles
Hello I applied the code but it keeps popping out error
WPBeginner Support
It would depend on the specific error but for the most common reasons you would want to take a look at our article here:
https://www.wpbeginner.com/beginners-guide/beginners-guide-to-pasting-snippets-from-the-web-into-wordpress/
管理者
John
The PHP code worked great, but how do I limit it to post pages only. Once I added the code to functions.php it displayed last updated on both pages and posts. What do I need to add to limit it to just posts?
Thanks,
John
WPBeginner Support
To limit it to posts you would use an if statement after the function:
function wpb_last_updated_date( $content ) {
if ( is_single() ) {
and add a closing
}
above the add_filter line管理者
John
Thank you for the quick response!
I tried the code, but it prevents my blog pages from rendering. However, my blog post pages continue to work and display last updated date.
Do you have any idea why that is?
WPBeginner Support
You may want to reach out to your theme’s support, this code shouldn’t prevent the rendering of content unless something theme-specific is conflicting with it.
Romeo
Still worked in September 2019 for one of my sites. For my Genesis based site, I needed to use the Genesis Simple Edits plugin to easily modify the post info since they put the post info in an array, instead of in a function.
WPBeginner Support
Thanks for sharing what worked for you
管理者
sarkariyojanainfo
Thank you for this post, I tried it and its working Fine..
WPBeginner Support
You’re welcome, glad our article could be helpful
管理者
Kirsty
Hi there,
I’m having the opposite problem – I have a new website and have backdated my posts to the date that they were originally created, but my site is showing the dates that they were last updated.
Any advice on how to fix this, or if there is a link to another tutorial for that somewhere would be greatly appreciated, I can’t find one!
Thanks.
WPBeginner Support
By default, WordPress should work like this, you may want to reach out to the support for the specific theme you’re using to see if they have a setting for this.
管理者
Giacomo
Hi, will it impact SEO if I show both the posted, and the updated date?
Thanks!
WPBeginner Support
Unless I hear otherwise, we haven’t tested the SEO impact of having both displaying at the same time but your post’s metadata should let search engines know which date to look at.
管理者
Noz
Thanks.. is there a way to show the Last modified field Only After certain time from date of post?
i.e if the next day you edited a post for some reason, doesn’t have to show as modified..
WPBeginner Support
Not at the moment but we can certainly look into an option to do that.
管理者
Bill Hogsett
i have a page that lists books that I have read and I update the page when I start a new book.
On the sit’s homepage I have a menu link to the book list. I would like to have button, or maybe just text, next to the homepage link showing the last time the book list page has been updated.
Any suggestions?
Thanks.
WPBeginner Support
You could either add a text widget or edit the menu item’s title manually when you update the page.
管理者
Herbert
I am using Method 1 since Method 2 doesnt seem to work on my theme. Is there a way to have the text be displayed n the bottom of the post? Your response would mean a lot. Thank you
WPBeginner Support
For relocating the publish date you would want to reach out to the support for the theme you are currently using for how to do that with your theme.
管理者
Pete
This is great. Quick question, I can’t seem to get it to only show on post and not pages? I tried to add method 2 to the single post template, but that didnt seem to work. It doesnt contain a bit about date or time. Even though the date is displayed in header.
Should i be adding more to show date and time in the single post template?
WPBeginner Support
Your specific theme may be pulling that information from another file. If you reach out to your specific theme’s support they should be able to assist.
管理者
Tudor
Hi, how to make last updated date show only on specific pages?
Alexander
Hi, thanks so much for this guidance freely given.
Suppose I do not want to show the published date but only the last updated date? How can I modify the code to achieve that, please?
Thanks
Alexander
WPBeginner Support
You would need to modify your theme’s templates, as each theme is different you would need to check with your theme’s support for where the published date is located
管理者
Melanie
Hi,
I found your information helpful. But perhaps you can answer two more questions:
When is it best to completely update a post aka republish it versus just provide the “last updated” information? Sometimes republishing something feels like cheating – it’s a lazy way to update my blog.
I’ve also read that having two dates on a post can confuse Google when it is crawling your site. Of course, I would like for them to pick up the latest date so it shows next to the description in the search results. Is there a way to show one or the other?
Right now, I have removed the entry date on posts while employing the “last updated” date (using css for both). Problem is that if I haven’t updated something, then it shows no date which is also a no-no according to the post above.
A LOT to address here, I know! But if you would be so kind to consider a reply, I would appreciate it.
Thanks!
WPBeginner Support
Hi Melanie,
It is best to simply update a post if changes are minor. However, if a post is completely outdated and a rewrite contains all new information, then you can publish it as a new article and redirect your old article.
管理者
Dat Nguyen
Thank you.
It so helpful.
I need it.
Christie
How do you keep the “last updated” from appearing at the top of specific pages. I really only want it on blog posts, not my homepage, contact page, etc.? thanks.
Laura
This code is excellent. Thanks so much. I’m following pretty much all of it, but I’m just curious what the 86400 number added to the updated time is doing.
Thanks in advance.
WPBeginner Support
Hi Laura,
86400 is number of seconds in a day. The code checks if the modified time is larger than or equals to a day.
管理者
Morsi
Hello, can i use the first méthod and using the translation file to translate it into my language ?
Sunny Mui
Thanks, this was helpful for implementing last updated text on my blog.
One point, the theme specific code is actually incorrect. You forgot the “echo get_…” before the get_the_modified_time() function.
Right now it just says:
the_modified_time(‘F jS, Y’);
echo ” at “;
the_modified_time();
When it should say:
echo get_the_modified_time(‘F jS, Y’);
echo ” at “;
echo get_the_modified_time();
Jamie Brower
Can you please tell me how to post the modified date AFTER the content. I tried using a in the footer.php but then it just displays before the content AND in the footer. I would just like the footer to display.
Daniele
Thanks guys, it works like a charm! A so so cool tip!
If you want to add the last modified ONLY ON POSTS, that works for me (I’m Italian and I edited it not showing the hour and modified the date order):
function wpb_last_updated_date( $content ) {
$u_time = get_the_time(‘U’);
$u_modified_time = get_the_modified_time(‘U’);
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time(‘d F Y’);
$updated_time = get_the_modified_time(‘H:i’);
$custom_content .= ‘Articolo aggiornato il ‘. $updated_date . ”;
}
if(is_single()){
$custom_content .= $content;
return $custom_content;
}
return $content;
}
add_filter( ‘the_content’, ‘wpb_last_updated_date’ );
David Aguirre
Dude, this is gold, I don’t know why anyone has thanked you before.
Thank you
PET
Yeah, good stuff! Thanks bro!
David
I have applied above all settings on my website and its working fine.
But I have one question that when two dates shown above content then which date will be shown in google search engine result page? Please provide answer because I have done all this only for showing last update date in google search engine result page.
ahmed
i like this it is very good and easy to install with genesis child theme function.php thank you
Vishal Mukherjee
Hi,
Added the following code to functions.php
function wpb_last_updated_date( $content ) {
$u_time = get_the_time(‘U’);
$u_modified_time = get_the_modified_time(‘U’);
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time(‘F jS, Y’);
$updated_time = get_the_modified_time(‘h:i a’);
$custom_content .= ‘Last updated on ‘. $updated_date . ‘ at ‘. $updated_time .”;
}
$custom_content .= $content;
return $custom_content;
}
add_filter( ‘the_content’, ‘wpb_last_updated_date’ );
Works fine for posts but … the same is displayed in Pages also.
I want it only for post. or if pages then at a different place eg End og the page article.
Best Wishes
Vishal Mukherjee
Victor Step
Thank you for the code.
However, there is a common problem that Google pulls the date of the embedded youtube video instead of the updated blog post date. In your case, I see that the search results do in fact show the correct date, and not the embedded video’s upload date. How did you achieve this? Thank you.
RUWAN
hello, I want only show updated date like your website, not both(updated and published date), when I add your code to site then its shows that both dates, please guide me to show only that updated date. thanks
Ludwig Sörmlind
Thank you for this post, I tried it and it works like a charm. I went for the site-specific plugin-option.
Ebuka
Thanks a lot it worked perfectly. but for the custom CSS only the “text-transform” worked on my theme. Other CSS like; color, text-weight, background-color etc. did not work. Please is there any possible way around it?
peter
hi syed ,am peter. the code work on my theme, but when i tried to add css style , i mean this code .last-updated {
font-size: small;
text-transform: uppercase;
background-color: #fffdd4;
}
my site goes blank. please what do i do to restore my website…
WPBeginner Support
Hi Peter,
We are not sure what may cause this. Just to be on the safe side, please take a look at our guide on how to add custom CSS in WordPress.
管理者
Steve W
Thank you for this tip. I actually turned it into a shortcode so that it only shows up where I want it, and not on every page or post. [last_updated]
Velyz Zhang
Hi,
Actually the code is work, but the result showing some numbers before “last update”
1494555840LAST UPDATED ON JUL 9, 2017
Every single post that I updated showing different numbers like that. Any one can help me?
Thank you
mathhew
Can you please explain how to apply it for genesis framework. i tried it but it didn’t worked
Adarsh Sahu
Hey I just tried this method it worked fine for me but the problem is that now my post is not showing any date in google search please help me i also want to show last updated date in Google search when anyone searches my content.
Filip
Hi
The code work great, thank you!
Can you tell us how to edit published time and add Published by “author” like in your images?
Chuks Ibe
I tried using this for my blog but it is also showing the “Last Updated” in the latest post page and its making it look like Last updated is part of the post content.
i need help to correct this thanks.