Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Puchar WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Jak wyświetlić datę ostatniej aktualizacji twoich wpisów w WordPressie?

Chcesz wyświetlać datę ostatniej aktualizacji twoich wpisów w WordPressie?

Niektóre witryny internetowe regularnie aktualizują swoje wpisy. Pokazanie, kiedy każdy wpis został zaktualizowany, daje pewność, że twoi czytelnicy nie przegapią żadnej treści, pomaga budować zaufanie i buduje autorytet, aby zwiększyć rankingi SEO.

W tym artykule pokażemy, jak wyświetlić datę ostatniej aktualizacji twoich wpisów w WordPress.

How to Display the Last Updated Date of Your Posts in WordPress

Dlaczego warto wyświetlać datę ostatniej aktualizacji twoich wpisów w WordPressie?

Gdy odwiedzający zobaczą wpis lub stronę na twoim blogu WordPress, twój motyw WordPress pokaże datę publikacji wpisu. Jest to dobre rozwiązanie dla większości blogów i statycznych witryn internetowych.

Jednak WordPress jest również używany przez witryny internetowe, w których stare artykuły są regularnie aktualizowane. W takich publikacjach importowane jest wyświetlanie daty i godziny ostatniej modyfikacji wpisu.

Na przykład na WPBeginner regularnie aktualizujemy nasze poradniki i pokazujemy datę „ostatniej aktualizacji” w każdym wpisie. Gdybyśmy wyświetlali tylko datę publikacji, nasi czytelnicy pominęliby wpis, zakładając, że informacje są nieaktualne.

Example of Showing the Update Date of a Post

Innym przykładem są witryny internetowe z wiadomościami. Często aktualizują one stare relacje, aby pokazać nowe utwórz, dodać poprawki lub wstawić pliki multimedialne. Gdyby pokazywały tylko datę publikacji, ich użytkownicy przegapiliby te aktualizacje.

Ponadto Google i inne wyszukiwarki lubią pozycjonować najbardziej aktualne informacje. Wyświetlanie daty aktualizacji pomaga Googlebotowi i innym wiedzieć, kiedy twój wpis był ostatnio aktualizowany.

Mając to na uwadze, przyjrzyjmy się, w jaki sposób można łatwo wyświetlić datę ostatniej aktualizacji twoich wpisów w WordPressie.

Film instruktażowy

Subscribe to WPBeginner

Jeśli wolisz poradnik w formie pisemnej, kontynuuj lekturę poniższego przewodnika.

Jak wyświetlić datę ostatniej aktualizacji twoich wpisów w WordPressie?

Ten poradnik wymaga dodania kodu do twoich plików WordPress. Jeśli nie robiłeś tego wcześniej, zalecamy zapoznanie się z naszym przewodnikiem na temat kopiowania i wklejania kodu w WordPress.

Metoda 1: Wyświetlanie daty ostatniej aktualizacji przed treścią wpisu

W tym poradniku będziemy używać WPCode, ponieważ jest to najbezpieczniejszy i najłatwiejszy sposób dodawania własnego kodu do WordPressa.

Edytowanie rdzennych plików WordPressa może być niebezpieczne, ponieważ nawet małe błędy lub literówki mogą zepsuć twoją witrynę. Dlatego zalecamy używanie WPCode do dodawania dowolnych fragmentów kodu.

Najpierw należy zainstalować i włączyć darmową wtyczkę WPCode. Aby uzyskać więcej informacji, zobacz nasz przewodnik krok po kroku, jak zainstalować wtyczkę WordPress.

Po włączeniu wtyczki, przejdź do Code Snippets ” Add Snippet w twoim kokpicie WordPress. Wyszukaj „datę ostatniej aktualizacji” i najedź kursorem myszy na wynik zatytułowany „Wyświetl datę ostatniej aktualizacji”.

Kod sprawdza, czy data publikacji i data ostatniej modyfikacji wpisu są różne. Jeśli tak, to wyświetla datę ostatniej modyfikacji przed treścią wpisu. (W ten sposób robimy to tutaj w WPBeginner).

Następnie wystarczy kliknąć przycisk „Użyj fragmentu kodu”.

WPCode searching for a snippet by name

Następnie zobaczysz ekran „Edytuj fragment kodu”. WPCode skonfigurowało już fragment kodu.

Wszystko, co musisz zrobić, to przełączyć przełącznik na „Włączanie” i kliknąć „Aktualizuj”, gdy będziesz gotowy.

WPCode edit snippet page and activate code

Ponieważ fragment kodu wyświetli zaktualizowaną datę przy użyciu stylów tekstu treści twojej witryny, możesz dodać własny CSS, aby nadać styl wyglądowi daty ostatniej aktualizacji. Oto mały fragment kodu CSS, który można wykorzystać jako punkt wyjścia:

.last-updated {
    font-size: small;
    text-transform: uppercase;
    background-color: #fffdd4;
} 

Tak to wygląda na naszej demonstracyjnej witrynie internetowej WordPress.

Dodatkowo, jeśli jesteś zaawansowanym użytkownikiem i czujesz się komfortowo, możesz dodać następujące funkcje do pliku functions.php twojego motywu.

Wystarczy połączyć się ze swoją witryną za pośrednictwem FTP lub menedżera plików hostingu WordPress i znaleźć plik w katalogu /wp-content/themes/yourthemename/ twojej witryny internetowej.

$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 );
}

Metoda 2: Dodawanie daty ostatniej aktualizacji w szablonach motywów

Możesz także wyświetlić zaktualizowaną datę zamiast opublikowanej daty lub tuż pod nią.

Ta metoda wymaga edycji określonych plików motywu WordPress. Pliki, które należy edytować, zależą od używanego motywu.

Wiele motywów WordPress wykorzystuje własne tagi szablonów do wyświetlania metadanych wpisów, takich jak data i godzina. Inne motywy używają szablonów treści lub fragmentów szablonu. Prostsze motywy używają plików single.php, archive.php i innych plików szablonów do wyświetlania treści i meta informacji.

Musisz poszukać pliku zawierającego kod odpowiedzialny za wyświetlanie daty i godziny. Następnie możesz zastąpić ten kod poniższym kodem lub dodać go bezpośrednio po kodzie daty i godziny twojego motywu.

$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> "; } 

Możesz usunąć linie 6 i 7, jeśli nie chcesz wyświetlać czasu aktualizacji wpisu.

Tak to wyglądało na naszej witrynie demonstracyjnej. W motywie Twenty Twenty-One dodaliśmy fragment kodu do pliku template-tags.php w katalogu inc.

Preview of Displaying Update Date by Editing Template

Jak zarządzać datą ostatniej aktualizacji twoich wpisów w WordPressie?

Teraz, gdy dodaliśmy datę ostatniej aktualizacji dla każdego wpisu, będzie ona automatycznie aktualizowana za każdym razem, gdy dokonasz zmiany w jakimkolwiek wpisie. Ale co, jeśli wprowadzasz tylko niewielką poprawkę, a nie pełną aktualizację, taką jak poprawienie błędu ortograficznego lub dodanie tagu?

W przypadku niewielkich zmian zwykle najlepiej jest pozostawić datę modyfikacji bez zmian z punktu widzenia SEO. Twoi czytelnicy zobaczą wtedy datę ostatniej dużej aktualizacji wpisu.

Oto kilka wtyczek, które pozwalają aktualizować wpisy bez zmiany daty modyfikacji.

Metoda 1: Korzystanie z wtyczki Limit Modified Date

Najpierw należy zainstalować i włączyć wtyczkę Limit Modified Date. Aby uzyskać więcej informacji, zobacz nasz przewodnik krok po kroku, jak zainstalować wtyczkę WordPress.

Uwaga: Ta wtyczka nie była ostatnio aktualizowana. Przetestowaliśmy ją jednak z najnowszą wersją WordPressa i nadal działa.

Po włączaniu zobaczysz nowe pole wyboru podczas edycji wpisów. Jest ono oznaczone jako „Nie aktualizuj daty modyfikacji”.

Checkbox Added by Last Updated Date

Gdy dokonujesz drobnej aktualizacji wpisu, po prostu zaznacz to pole, a data modyfikacji nie zostanie zmieniona.

AIOSEO znane również jako All in One SEO to najlepsza wtyczka WordPress SEO na rynku. Pomaga poprawić rankingi wyszukiwania bez uczenia się skomplikowanego żargonu, dzięki czemu możesz zwiększyć ruch na swojej witrynie internetowej.

Możesz dowiedzieć się więcej z naszego przewodnika na temat tego, jak poprawnie skonfigurować All in One SEO dla WordPress.

Jeśli korzystasz już z AIOSEO, aby poprawić swoje rankingi w wyszukiwarkach, możesz również użyć go do zarządzania datą modyfikacji twoich wpisów.

Po włączaniu znajdziesz nowe pole wyboru podczas edycji wpisów, oznaczone jako „Nie aktualizuj daty modyfikacji”. Możesz zaznaczyć to pole podczas wprowadzania drobnych zmian we wpisie.

Jest to przydatne w przypadku zwykłej poprawki literówek lub prostych błędów, a pole można odznaczyć w przypadku wprowadzania zmian, o których czytelnicy i wyszukiwarki mają wiedzieć.

Checkbox Added by AIOSEO

Mamy nadzieję, że ten poradnik pomógł ci dowiedzieć się, jak wyświetlać datę ostatniej aktualizacji twoich wpisów w WordPressie. Możesz również dowiedzieć się, jak przyspieszyć działanie WordPress a lub zapoznać się z naszą listą sprawdzonych wskazówek, jak zwiększyć ruch na twoim blogu.

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.

Ujawnienie: Nasze treści są wspierane przez czytelników. Oznacza to, że jeśli klikniesz na niektóre z naszych linków, możemy otrzymać prowizję. Zobacz jak WPBeginner jest finansowany, dlaczego to ma znaczenie i jak możesz nas wspierać. Oto nasz proces redakcyjny.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Najlepszy zestaw narzędzi WordPress

Uzyskaj BEZPŁATNY dostęp do naszego zestawu narzędzi - zbiór produktów i zasobów związanych z WordPressem, które każdy profesjonalista powinien mieć!

Reader Interactions

147 komentarzyZostaw odpowiedź

  1. 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!

  2. Bobbi

    How do you get Bing to pull the updated date as opposed to the original published date? I have it set up so that Google does, but Bing doesn’t seem to want to

    • WPBeginner Support

      If you just recently added this then you would need to give Bing time to recrawl your site’s content.

      Administrator

  3. 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.

      Administrator

  4. 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.

      Administrator

  5. 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
      }

      Administrator

  6. 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!

      Administrator

  7. 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.

      Administrator

  8. 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.

      Administrator

  9. 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.

      Administrator

  10. 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 :)

      Administrator

    • Gianluigi Filippelli

      if ( get_post_type() 'page’ ){
      return $custom_content;
      } else {
      return $content;
      }

  11. 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 :)

      Administrator

  12. 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.

      Administrator

  13. 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.

      Administrator

  14. 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 :)

      Administrator

  15. 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 :)

      Administrator

  16. ali karimi

    thanks a lot for your help

    • WPBeginner Support

      You’re welcome :)

      Administrator

  17. 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

      Administrator

  18. 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.

      Administrator

  19. Charles

    Hello I applied the code but it keeps popping out error

  20. 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

      Administrator

      • 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.

  21. 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

      Administrator

  22. sarkariyojanainfo

    Thank you for this post, I tried it and its working Fine..

    • WPBeginner Support

      You’re welcome, glad our article could be helpful :)

      Administrator

  23. 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.

      Administrator

  24. 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.

      Administrator

  25. 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.

      Administrator

  26. 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.

      Administrator

  27. 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.

      Administrator

  28. 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.

      Administrator

  29. Tudor

    Hi, how to make last updated date show only on specific pages?

  30. 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

      Administrator

  31. 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.

      Administrator

  32. Dat Nguyen

    Thank you.
    It so helpful.
    I need it.

  33. 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.

  34. 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.

      Administrator

  35. Morsi

    Hello, can i use the first méthod and using the translation file to translate it into my language ?

  36. 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();

Zostaw odpowiedź

Dziękujemy za pozostawienie komentarza. Pamiętaj, że wszystkie komentarze są moderowane zgodnie z naszymi polityka komentarzy, a Twój adres e-mail NIE zostanie opublikowany. NIE używaj słów kluczowych w polu nazwy. Przeprowadźmy osobistą i konstruktywną rozmowę.