Sort posts by modification date in WordPress

By default, WordPress sorts blog posts by creation date. However, if you update your blog posts from time to time, you may want to sort them by modification date rather than creation date.

To achieve this, use this snippet:

function order_posts_by_mod_date($orderby) {
  if  (is_home() || is_archive() || is_feed()) {
    $orderby = "post_modified_gmt DESC";
  }

  return $orderby;
}

add_filter('posts_orderby', 'order_posts_by_mod_date', 999);

In your theme, just dump this snippet into functions.php. (You may need to create this file in your theme’s directory.)

Upload arbitrary files to WordPress (new plugin)

WordPress is very restrictive when it comes to file uploads. It’s for security reasons, mainly to prevent bad-behaving users to upload PHP scripts and the like to the blog.

However, if you’re the only one writing posts for your blog, this restriction sometimes is annoying. For example, I do a lot coding in C#. So, when I try to upload a .cs file (C# source code file) to my blog, the upload is rejected.

Wordpress rejected upload with "Sorry, this file type is not permitted for security reasons."

Files are approved or rejected based on their file extension, i.e. the few characters after the dot in the file name, like cs in ArrayClearTest.cs.

WordPress maintains an internal list of which file extensions are allowed. Fortunately, WordPress also allows for this list to be extended.

And that’s what my new WordPress plugin does. It’s called Upload File Type Settings Plugin and allows you to extend that list with an easy-to-use user interface. Go, give it a try.

The plugin's settings page.

BlogText – the new blog text

I’ve just finished my first WordPress plugin. It’s called BlogText and provides a nice, easy, alternative syntax (im comparison with HTML) for writing blog posts. I’ve been working on the for the past couple of months and now it’s finally finished — at least its first version. You can find it here:

http://blogtext.mayastudios.com

Give it a try. You might like it