WordPress – Theme Editor: Alphabetical File Sorting

A quick fix some people might be interested in is how to sort the files listed on the theme editor page alphabetically. Some themes can have a large number of files and the default WordPress coding puts the list in no particular coding, making it difficult to track down a particular page. The addition of 2 lines of code can order the list to make it easier to work with.

  1. Save a copy of wp-admin/theme-editor.php to your local computer
  2. Backup the original version
  3. Open the local copy with a plain text editor (notepad works nicely)
  4. Around line 35 there should be a statement identical to:
    $allowed_files = array_merge($themes[$theme][‘Stylesheet Files’], $themes[$theme][‘Template Files’]);
  5. After this insert the following two lines directly after:
    natcasesort($allowed_files);
    $allowed_files = array_values($allowed_files);
  6. Save your copy and upload it back to the server
  7. Presto, list of files is now in alphabetical order

This will order by filename, but some files might display aliases like “Stylesheet” instead of styles.css, but it will still sort using styles.css, just be aware of that.

21 Replies to “WordPress – Theme Editor: Alphabetical File Sorting”

  1. Thanks for your input on my beginner web design stuff. Who do you use for hosting? If I am parked at GoDaddy, how do I switch from there to another host? I was at the store tonight and was looking at Microsoft FrontPage. I thought it might be good because you can work with or without code, but with both screens side by side. I thought it might be a good teaching tool. Plus it allowed for designing an ecommerce sight, which I might like to do at some point. What do you think?

  2. I’d like to suggest you say no to frontpage (it gets technical why)! Use Macromedia Dreamweaver, it’s a good product as far as pay for web design / layout software goes, WYSWIG and all that beginner friendly stuff but can be used to produce advanced pages also…

  3. You should put up a post including some of your recent photographic work. I don’t know, just what I want to see next.

  4. Thank you very much for this little fix… I’d been puzzling over a way to sort by alphabetical order the files in the theme because I have a ton of custom files in there (over 40). I wish that they’d put this in the admin permanently…

  5. I had the order just the way I wanted it. I transferred to a new server and now it’s all out of whack. What usually causes it to change order like that?

  6. unbelievable. i have no idea why this isn’t the default behaviour. thank you so much for this fix/hack!

  7. This isn’t working for me and I can’t find any other reference to this problem. Has something changed in 2.+ versions to make this not work?

  8. @Internet Marketing Overload

    There is a WYSIWYG theme editor plugin for Dreamweaver called ThemeDreamer for WordPress. If you don’t have it, you’re only getting half the picture!

    do a google search on ThemeDreamer and see the screenshots for before/afters

  9. Hi, I want to learn how come I put alphabetic list in all my posts blog messages. Need plugin? or just configuration any php? thanks!

  10. That’s super useful. I’m building a shopping cart for a customer with tons of products. Any idea how to get wp to sort the products alphabetically?

  11. It works like a breeze. We have upgraded to WP 2.8 but with the default coding inplace, it was rather difficult to locate relevant pages. Your two lines of code proved invaluable.

Comments are closed.