Add Custom Size Image to Media Popup in WordPress

In WordPres 4.5, my old function to add a custom size to media uploader seems not working anymore. But I found that new way to add custom size image is a lot simpler using image_size_names_choose filter.

Basically when you create your own image sizes using the add_image_size function:

you can just add the new sizes to image_size_names_choose:

Screen Shot 2016-06-06 at 4.36.51 PM

PHP, snippet, Wordpress, , Leave a comment

Get Page ID or URL From a Slug in WordPress

This is interesting, with years experience working with WordPress, I’ve never dealt with this kind of issue. I searched the codex, and found get_page_by_path is the ideal solution instead of directly create query to database.

To get a page ID simply add the slug to the function

I creates a function to simplify the usage

And use it in real life


PHP, snippet, WordpressLeave a comment

How to Display and Order Users on a Page

If you have registered users on certain role, to list them on a single page, you can use WP_User_Query

Here’s the basic loop:

You can list and order the result by adding array value, in below example I would like to order user by last name, the $arg array value should like:

That’s it let me know if you have any questions.

PHP, snippet, Wordpress, , Leave a comment