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

Så här visar du det senaste updating-datumet för dina publicerade posts i WordPress

Vi har drivit WordPress-webbplatser i över ett decennium och en funktion som vi alltid rekommenderar är att visa när ett inlägg senast uppdaterades. Det är en liten detalj som gör stor skillnad.

Det är därför vi på WPBeginner visar det senast uppdaterade datumet på alla våra inlägg. Det visar läsarna att vårt innehåll är färskt, korrekt och pålitligt.

Vad många webbplatsägare inte inser är att detta också kan hjälpa till med SEO. Sökmotorer föredrar innehåll som uppdateras regelbundet.

När besökarna ser att dina inlägg är aktuella är det mer troligt att de stannar kvar på din webbplats och litar på vad du säger.

I den här guiden visar vi dig flera sätt att visa det senaste uppdateringsdatumet för inlägg i WordPress.

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

Varför visa det senaste updating-datumet för dina publicerade posts i WordPress?

När besökare tittar på ett inlägg eller en sida på din WordPress-blogg kommer ditt WordPress-tema att visa datumet då inlägget publicerades. Detta är bra för de flesta bloggar och statiska webbplatser.

WordPress används dock även av websites där gamla artiklar uppdateras regelbundet. I dessa publikationer är det viktigt att visa datum och tid då posten senast ändrades.

Till exempel på WPBeginner uppdaterar vi regelbundet våra tutorials och visar datumet för “senast uppdaterad” på varje post. Om vi bara visade det publicerade datumet skulle våra läsare hoppa över posten och anta att informationen är inaktuell.

Last Updated in WPBeginner

Ett annat exempel är nyhetswebbplatser. De uppdaterar ofta gamla relacjor för att visa nya händelser, lägga till rättelser eller wstawić mediefiler. Om de bara visade publiceringsdatumet skulle användarna missa dessa uppdateringar.

Dessutom gillar Google och andra search engines att ranka den mest uppdaterade informationen. Displaying your updated date hjälper Googlebot och andra att veta när posten senast rördes.

Hur man visar det senaste updating-datumet för dina publicerade posts i WordPress

Den här poradniken kräver att du lägger till kod i dina WordPress-filer. Om du inte har gjort det tidigare rekommenderar vi att du tar en titt på vår przewodnik om hur du kopierar och klistrar in kod i WordPress.

Med detta i åtanke ska vi visa dig 2 metoder för att enkelt visa det senaste uppdateringsdatumet för dina inlägg i WordPress. Du kan gå vidare och klicka på hopplänkarna nedan för att använda den metod du föredrar.

Låt oss komma igång!

Metod 1: Visa senast uppdaterade datum före postens innehåll

Du kan enkelt visa det senaste uppdateringsdatumet före ditt innehåll genom att lägga till anpassad kod på din webbplats. Men även det minsta felet i koden kan göra din webbplats otillgänglig.

Det är därför vi rekommenderar att du använder WPCode. Vi har testat det noggrant och funnit att det är det säkraste och enklaste sättet att lägga till anpassad kod.

För att lära dig mer om vår erfarenhet, kolla in vår WPCode recension.

Först måste du installera och aktivera det gratis pluginet WPCode. För mer information, se vår Step-by-Step guide om hur du installerar ett WordPress plugin.

WPCode's homepage

Obs: Premiumversionen av WPCode har fler funktioner! Så om du gillar gratisversionen kan du uppgradera och njuta av ett privat molnbibliotek, konverteringspixeltillägg, inbyggda åtkomstkontroller och stöd för flera webbplatser. För att lära dig mer om pluginet kan du gå igenom vår fullständiga WPCode-recension.

När pluginet är aktiverat navigerar du till Code Snippets ” + Add Snippet i din kokpit på WordPress. Sök efter “senast uppdaterade datum” och håll muspekaren över resultatet med titeln “Visa senast uppdaterade datum”.

Koden kontrollerar om ett posts publicerade datum och senast ändrade datum är olika. Om de är det, så visas det senast ändrade datumet före postens content. (Det är så vi gör det här på WPBeginner.)

Därefter kan du bara klicka på knappen “Använd snippet”.

WPCode searching for a snippet by name

Därefter kommer du att se vyn “Edit Snippet”. WPCode har redan konfigurerat snippet åt you.

Allt du behöver göra är att toggle omkopplaren till “Active” och clicka “Update” när du är klar.

WPCode edit snippet page and activate code

Eftersom fragmentet kodu kommer att visa det uppdaterade datumet med hjälp av webbplatsens brödtextstilar, kan du lägga till anpassad CSS för att forma utseendet på det senast uppdaterade datumet.

Här är ett litet CSS-fragment kodu som du kan använda som utgångspunkt:

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

Och så här ser det ut på vår demo WordPress-webbplats:

Last updated example on a live website

Dessutom, om du är en avancerad användare och känner dig bekväm med att göra det, kan du add to följande till ditt temas functions.php-fil.

Anslut bara till din webbplats via FTP eller via filhanteraren på ditt WordPress-värd och hitta filen i webbplatsens mapp /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 );
}

Metod 2: Lägga till senaste Updated Date i Theme Templates

Du kan också visa det uppdaterade datumet i stället för det publicerade datumet eller precis under det.

Den här metoden kräver att du redigerar specifika WordPress-temafiler. Vilka filer du behöver redigera beror på vilket tema du har.

Många WordPress-teman använder sina egna template tags för att visa metadata för poster som gillar datum och tid. Andra teman använder innehållsmallar eller malldelar. Enklare teman använder single.php, archive.php och andra mallfiler för att visa content och metainformation.

Du måste leta efter den fil som innehåller den kod som ansvarar för att visa datum och tid. Sedan kan du antingen ersätta den koden med följande kod eller lägga till den direkt efter ditt temas datum- och tidskod.

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

Om du inte vill visa när inlägget uppdaterades kan du gå vidare och usunąć raderna 6 och 7.

Så här såg det ut på vår demo site. Med temat Twenty Twenty-One adderade vi code snippet till filen template-tags.php i mappen inc.

Preview of Displaying Update Date by Editing Template

Bonustips: Så här hanterar du det senaste uppdateringsdatumet för dina inlägg

Nu när vi har addat det senast uppdaterade datumet för varje post kommer det automatiskt att update varje gång you gör en ändring i en post. Men vad händer om du bara gör en liten korrekt snarare än en fullständig update, som att fixa ett stavfel eller lägga till en tagg?

För små ändringar är det oftast bäst att lämna det ändrade datumet oförändrat ur ett sökmotorsoptimeringsperspektiv. Dina Läsare kommer då att se datumet för när den senaste större updatingen gjordes på posten.

AIOSEO, även känt som All in One SEO, är det bästa SEO-pluginet för WordPress på marknaden. Det hjälper dig att förbättra sökrankingen utan att lära dig komplicerad jargong, så att du kan öka din webbplatstrafik.

AIOSEO's homepage

Om du redan använder AIOSEO för att förbättra din search engine ranking, kan du använda den för att hantera det ändrade datumet för dina posts också.

Om du inte har gjort det är det första du måste göra att installera och aktivera AIOSEO. Du kan läsa mer i vår przewodnik om hur du installerar All in One SEO för WordPress på rätt sätt.

Obs: Du kan använda gratisversionen av AIOSEO för att göra den här uppgiften. Men genom att köpa pro-versionen kommer du att kunna komma åt avancerade funktioner som ChatGPT AI-verktyg, spårning av innehållsförfall, en omdirigeringshanterare och en intern länkassistent. För mer information kan du läsa vår fullständiga AIOSEO-recension.

Vid aktivering hittar du en ny kryssruta märkt “Uppdatera inte ändringsdatumet” när du redigerar inlägg. Du kan markera rutan när du gör mindre ändringar i ett inlägg.

Checkbox Added by AIOSEO

Det här är användbart när du ska poprawka stavfel eller enkla misstag, och du kan avmarkera rutan när du gör ändringar som du vill att dina läsare och sökmotorer ska känna till.

Video Tutorial

Behöver du en visuell przewodnik? Då kanske du uppskattar vår snabba videoguide med WPCode:

Subscribe to WPBeginner

Vi hoppas att denna handledning hjälpte dig att lära dig hur du visar det senast uppdaterade datumet för dina inlägg i WordPress. Du kanske också vill lära dig hur du inaktiverar Google Fonts på din WordPress-webbplats, och vår lista över utmärkta WordPress-webbplatsexempel som du bör kolla in.

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

147 kommentarerLeave a Reply

  1. Thanks for the snippet. It works perfectly. I have a bilingual website and I edited the snippet using AI so that it was in the correct language mutation on both the CZ and EN versions. But I used your snippet as a basis and it works great.

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

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

      Admin

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

      Admin

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

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

      Admin

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

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

      Admin

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

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

    • It should not cause an issue, you would mainly need to give time for Google to recrawl your updated dates.

      Admin

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

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

      Admin

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

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

      Admin

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

    • 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 :)

      Admin

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

    • You would want to reach out to the support for your specific theme and they should be able to assist with that placement.

      Admin

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

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

      Admin

    • 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

      Admin

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

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

      Admin

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

    • 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

      Admin

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

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

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

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

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

      Admin

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

      Admin

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

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

    • You could either add a text widget or edit the menu item’s title manually when you update the page.

      Admin

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

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

      Admin

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

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

      Admin

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

    • 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

      Admin

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

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

      Admin

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

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

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

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.