Adding an update status next to post titles in WordPress


Note :This snippet works only with the Classical style option. The Classical style option can be enabled in Appearance > Customize > Advanced > Theme Style. More about the theme style option here


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.

adding-an-update-status-to-posts-WordPress

 

Important : In the Customizr theme, use the  'tc_content_headings' filter instead of 'the_title' . 

 

  

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.


Related Snippets you may also like


We can help you to implement this snippet

Coding is our job and we know WordPress inside and out. We can help you to customize your website with small chunks of code snippets like this one.

Send us your request and we'll get back to you quickly.



34 thoughts on “Adding an update status next to post titles in WordPress

  • Cedric

    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

  • Majid

    Hey Nicholas
    I have been researching on how to show in blog/page recently update post first instead of old post in blog

  • Shiv

    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

    • Nicolas Post author

      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 🙂

  • Carlo

    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.

  • Belqadi

    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

  • Belqadi

    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,

  • Belqadi

    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.

  • Belqadi

    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

  • Aleks

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

    • Giorgio25b

      Aleks, thanks for the snippett. I just made it ctrl+c friendly

  • Brad Dalton

    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.

  • Aleks

    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

  • arno

    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

  • Arno KReuer

    Hallo Nicolas, a little thing but it should instead “tc_content_headings ‘right’ tc_content_headings ‘be? Only a’ Greetings Arno

  • 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

  • Arno Kreuer

    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

  • Arno Kreuer

    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

  • Arno Kreuer

    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!

Comments are closed.