This simple snippet adds an update status after your post title in WordPress.
It checks if the post has been updated since its creation and if this update is less than n days old. If the condition is verified, it adds an update status text after the title. In this example, the update interval is set to 7 days.
The update status text is styled with a nice colored label class. Check the documention to get more informations about the Twitter Bootstrap components available in the Customizr theme.
Important : In the Customizr theme, use the ‘tc_content_headings’ filter instead of ‘the_title’ .
add_filter('the_title' , 'add_update_status'); function add_update_status($html) { //First checks if we are in the loop and we are not displaying a page if ( ! in_the_loop() || is_page() ) return $html; //Instantiates the different date objects $created = new DateTime( get_the_date('Y-m-d g:i:s') ); $updated = new DateTime( get_the_modified_date('Y-m-d g:i:s') ); $current = new DateTime( date('Y-m-d g:i:s') ); //Creates the date_diff objects from dates $created_to_updated = date_diff($created , $updated); $updated_to_today = date_diff($updated, $current); //Checks if the post has been updated since its creation $has_been_updated = ( $created_to_updated -> s > 0 || $created_to_updated -> i > 0 ) ? true : false; //Checks if the last update is less than n days old. (replace n by your own value) $has_recent_update = ( $has_been_updated && $updated_to_today -> days < 7 ) ? true : false; //Adds HTML after the title $recent_update = $has_recent_update ? '<span class="label label-warning">Recently updated</span>' : ''; //Returns the modified title return $html.' '.$recent_update; }
Where to paste this code? => in your functions.php file. I strongly recommend to create a child theme. Download a start-up child theme here.
Everything you need to know about child theme with Customizr here.
35 thoughts on “Adding an update status next to post titles in WordPress”
Hi Nicolas,
I don’t display my last WordPress posts in my home page, but access them with an item called ‘Events’ in the menu bar.
Is it possible to add a new status to this menu item when the last WP post arrived ? or the number of the last WP posts.
Thanks,
Cédric
Hey Nicholas
I have been researching on how to show in blog/page recently update post first instead of old post in blog
Hi,
I updated the theme a while ago and something seems to have broken since then. The “recently updated” snippet is showing in title and also in the footer.
Apparently am seeing some code also being displayed in the footer of all pages/posts in my website. Eg > http://www.lakshmisharath.com/2014/01/31/sea-sky-tirupullani-near-rameshwaram/
You can notice that near the end of the blog at the place where there is about author section there is some code/junk text coming up.
Is there a way i can fix this or atleast revert this to a older stable version.
Looking forward to your reply
Cheers,
Shiv
Hi,
I have checked your website and your issue.
It seems to be related to a conflict between the theme and a social sharing plugin.
What is the plugin you use to display your social sharing buttons ? I need to test it.
Can you try to disable it and see if the problem persists ?
Thanks 🙂
Hi Nicolas,
Sorry for my English.
I’m using Customizr 3.1.19 and I have the same problem when I use Google webmaster tools:
Error: Missing required field “entry-title”.
Error: Missing required field “updated”.
Error: Missing required hCard “author”.
I have those problems in the pages, not in the post’s.
Do you solve those errors in the new versions?
Some suggestions to solve?
Thank you.
Hey Nickolas,
Based on our previous comments,you said that you are going to address the Errors . You said that the Errors in Google Structured Data : Error: Missing required field “entry-title”.
Error: Missing required field “updated”.
Error: Missing required hCard “author”. will be included for v3.1.22 improvement! https://www.google.com/webmasters/tools/richsnippets?q=http%3A%2F%2Fppcsuccesscenter.com
I have updated your theme to v3.1.22. But I still have the same issues on Google Structured Data.
Any feedbacks please. Any remedies to solve that please ?
Regards
Hi Belqadi, I am working on somehting to fix it. It’s not ready yet, not that simple to implement 😉
Thanks
Hey Nick,
Thank you. I will be waiting for the new version.
Regards,
Hello Nicolas,
Could you help please ? I have these Errors for the Root URL when I use Google webmaster tool – Structured Data Testing Tool
https://www.google.com/webmasters/tools/richsnippets?q=http%3A%2F%2Fppcsuccesscenter.com
Error: Missing required field “entry-title”.
Error: Missing required field “updated”.
Error: Missing required hCard “author”.
Any recommendation or solution to fix that please. I tried this link but it did not help http://wordpress.org/support/topic/error-schema-data-google-web-tools and this also http://harry.subnetworx.de/2014/01/04/wordpress-theme-customizr-missing-required-field-updated/. But in vain.
I will be thankful to let me know how.
Regards,
Hi Belqadi,
YOu might want to read the following topic in the forum where the same issue has been reported : http://wordpress.org/support/topic/error-schema-data-google-web-tools
Hope this will help
Salut Nick,
Please note that Link does Not help solve those issues. Kindly note also that I included that link in my first comment to tell you that the link you gave me it did not provide any quality instructions or solutions for the above Errors.
Could you please help?
Thank you in advance
Regards
Hi Belqadi, here are some other post / forum topic from users who have fixed this issue :
http://harry.subnetworx.de/2014/01/04/wordpress-theme-customizr-missing-required-field-updated/
http://wordpress.org/support/topic/customizr-and-hfeed-warning?replies=8
Hope this helps and I look forward to reading from you.
Bonjour Nick,
The links you refered me I tried them now and before!!
The links you recommended to me are useless by now because many things have been changed in your theme as per updates. I mentioned those links in my first comment above when I addressed the current issues.
Could you please have sometime and investigate that ? You are going to help me and others with the same issues. I hope you get back with a solution. This is my URL in Google webmaster tool. https://www.google.com/webmasters/tools/richsnippets?q=http%3A%2F%2Fppcsuccesscenter.com
I am impatiently looking to hear from you.
Regards.
Hi,
I have included this fix in the list of improvements for v3.1.22.
Thanks
Hi Nicolas,
Thank you for your reply.
Indeed, I had looked in that link before contacted you here in my first comment above.
As you know, some folders and files has been changed its names with the new Version of your theme. Could you please tell me which file name is located the snippet to modify it ? Anything to help please locate the right file and right snippet causing Errors of
Error: Missing required field “entry-title”.
Error: Missing required field “updated”.
Error: Missing required hCard “author”.
Thank you so much once again, most importantly for the follow up.
Hello folks,
Help please.
I have the latest version of Customizer now 3.1.19. I am using a child theme. With the new version, I couldn t see the above files.
Any help regarding How to Fix these issues on Structured Data Testing Tool. I got these issues when I tried to Preview my homepage on Webmaster tools i,e http://www.mywebsite.com
Error: Missing required field “entry-title”.
Error: Missing required field “updated”.
Error: Missing required hCard “author”.
Your help is most appreciated.
Regards
Hi Belqadi, this has been addressed here.
Best
Sorry, I had to use a syntax highlighter 🙁
I’d like to share a solution for my question above.
I’ve modified code above, to display a “NEW”-status in the title.
Maybe my code is quick & dirty, but it works for me. I don’t know anything about php, just some about programming microcontrollers. So, I figured out, I’ve to modify some variables.
add_filter(‘tc_content_headings’ , ‘add_created_status’);
function add_created_status($html) {
//First checks if we are in the loop and we are not displaying a page
if ( ! in_the_loop() || is_page() )
return $html;
//Instantiates the different date objects
$created = new DateTime( get_the_date(‘Y-m-d g:i:s’) );
$current = new DateTime( date(‘Y-m-d g:i:s’) );
//Creates the date_diff objects from dates
$created_to_today = date_diff($created, $current);
//Checks if the post is “fresh”
$has_been_created = ( $created_to_today -> s > 0 || $created_to_today -> i > 0 ) ? true : false;
//Checks if the post ist n days old to remove NEW-status (replace n by your own value)
$is_new_post = ( $has_been_created && $created_to_today -> days < 7 ) ? true : false;
//Adds HTML after the title
$recent_post = $is_new_post ? 'NEW‘ : ”;
//Returns the modified title
return $html.’ ‘.$recent_post;
}
Aleks, thanks for the snippett. I just made it ctrl+c friendly
add_filter('the_title' , 'add_created_status'); // hook for all WP themes //add_filter('tc_content_headings' , 'add_created_status'); //hook only for Customizr function add_created_status($html) { //First checks if we are in the loop and we are not displaying a page if ( ! in_the_loop() || is_page() ) return $html; //Instantiates the different date objects $created = new DateTime( get_the_date('Y-m-d g:i:s') ); $current = new DateTime( date('Y-m-d g:i:s') ); //Creates the date_diff objects from dates $created_to_today = date_diff($created, $current); //Checks if the post is "fresh" $has_been_created = ( $created_to_today -> s > 0 || $created_to_today -> i > 0 ) ? true : false; //Checks if the post ist n days old to remove NEW-status (replace n by your own value) $is_new_post = ( $has_been_created && $created_to_today -> days < 7 ) ? true : false; //Adds HTML after the title $recent_post = $is_new_post ? 'NEW' : ''; //Returns the modified title return $html.' '.$recent_post; }
Thanks
hi Nicolas
I want a code for changing any text of my post title name of WordPress website.
As my post name is SSC 10+2 Admit Card 2020 New, Nicolas I want to change color of the text ” New ” only.
Please help me
Thanks for this contribution Aleks!
Just discovered this function in_the_loop() which is great for use with filters.
What i did was modify the the entry header meta post date to display the updated date.
Thanks for sharing this tip Brad!
Thank you for really amazing theme and useful code snippets.
I would be happy about similar solution (or extension for the code above), for new posts 🙂
I have modified my functions.php in the child theme and sort all posts by last update.
function filter_order() {
if(!is_admin() || !is_feed()) :
global $wp_query;
$wp_query->set(‘orderby’,’modified’);
endif;
}
add_action(‘pre_get_posts’,’filter_order’);
Now there are new and updated post on the top, and it’s a little bit puzzling 😀
Thanks in advance
Aleks
Hello Nicolas, if I install plugin qTranslate , I receive if the date ‘s display at the post widget : Home % A 28UTCSat , 28 Dec 2013 12:44:01 +0000 % e % B% Y without plugin : Top 28 December 2013. No problem for me is not necessary, but for info .
I have not found a solution for webmasters Goggles updatet . With the solution sprintf ( ‘ % 4 $ s ‘ , is not updatet but red : Error : At least one field must be set for Hcard .
Error: Missing required field “name (fn) ” .
The two snippets Adding an update status next to post titles in wordpress + Displaying the last post update ‘s date in the post metas is now a current dates but Google comes back with H atom -entry :
entry-title : Home
http://www.heilpraktiker-arno-kreuer.de/author/arnokreuer
bookmark :
name : updated January 12, 2014
rel : bookmark
url: http://www.heilpraktiker-arno-kreuer.de/2013/12/28
Error: Missing required field ” updated” .
Google sees above and below gives an updated error message ? ?
I also have a page Google Blogger , here is the error message. Thus Google has its own blog program is not correct!
Have a nice weekend
Thanks for these feedback Arno!
Hallo Nicolas, a little thing but it should instead “tc_content_headings ‘right’ tc_content_headings ‘be? Only a’ Greetings Arno
Hi Nicolas, I also have the 2 snippets http://www.presscustomizr.com/snippet/adding-an-update-status-to-posts-in-wordpress/
http://www.presscustomizr.com/snippet/displaying-last-post-updates-date-post-metas/
inserted in my child theme, ok but then comes back this error updatet from webmaster tool. when I have these 2 snippets removed now: Error: At least one field must be set for Hcard.
Error: Missing required field “name (fn)”. This was not previously, but updatet see is ok! I have thanks to your Hinweisses with sprintf (‘ % 4 $ s ‘, fixed.
Have an idea? Best regards Arno
Hallo Nicolas, Thanks so far. I’ll keep looking my way forward. Your program is worth the sweat. It is certainly great. Your pages are full of ideas, so I will solve my problems. Now proud to introduce the Child theme to have run on, was not as easy as one way did not work! Sorry my english is bad and with programming, therefore, very difficult, I hope the translation. Now I hope you can find a solution with Google Webmaster, then I can sleep well! All the best
Hello, thank you! Yes I have used this code last night. Yes, it is well with the post but not in the page. But it seems to unity in the forums that no one really understands where the problem Google has with Author, updatet.
I wonder if I copied your code Adding an update status next to post titles in wordpress to the wrong line. Which line would be correct? Or it does not affect page? Why does not have the pages no author, no date? Thanks
Hi Arno,
About Google rich snippet, I will work on a snippet about it.
you might want to read those resources to start customizing your theme : http://www.presscustomizr.com/customizr/how-to-customize-customizr-wordpress-theme/
It will answer all those questions.
Thanks
Hi, this issue has been resolved in the user forum : http://wordpress.org/support/topic/customizr-and-google-structured-data-testing-tool?replies=2
Hope this will help!
Hello, I find your creation super. Could not you offer a few more extras to buy?
Unfortunately I have no success with the above code. In which row should he? If not then the update date appear on the first date of creation? Google goes on to say: Error: Missing required field “updated”. like on your page:
http://www.google.com/webmasters/tools/richsnippets?q=http%3A%2F%2Fwww.presscustomizr.com%2Fsnippet%2Fadding-an-update-status-to-posts-in-wordpress%2F
Sorry for not understanding!