Feb 282009
For developing the website leren.arabisch.nu, I wanted to display the last date and time any page was updated. Because currently no plugin exists that can do this, I used the following shortcode definition:
add_shortcode('mb_last_modified', 'mb_last_modified_func'); function mb_last_modified_func($atts) { global $wpdb; $last_modified = $wpdb->get_var("SELECT MAX($wpdb->posts.post_modified) FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish'"); return date(get_option("date_format") . " " . get_option("time_format"), strtotime($last_modified)); } |
If you want to use this shortcode, put the code in the file functions.php of your theme. Create this file if it does not exist; WordPress will automatically find and use it. After that you can use the shortcode [mb_last_modified] anywhere in your posts and/or pages. If you want to use the shortcode in a widget just like I did, you have to add the following line of code too:
add_filter('widget_text', 'do_shortcode'); |




Hey, this is nice. Is there a way to specify date and time formatting options? It kind of looks like there might be from the source code, but I’m not really very familiar with WordPress shortcodes.
The code uses the date and time formatting settings of WordPress (Settings | General from the Dasboard).
Oh, right on. Many thanks. I’ll give you some credit on our Ingredients page. Tally-ho!
Not was i was looking for but still, thanks for contributing