PHP Random String From Array In WordPress

When I struggle to find a clear answer to something and eventually come up with something that works, I like to repost it here so others can hopefully save themselves some time. This is one of those times.

If you want to display a random string from an array in WordPress, such as a random quote from a collection of your favourites, I’m going to show you how. Note that this isn’t a WordPress-specific solution, but I like WordPress and I like when you do too so I’m going to assume you’re using it*.

Continue reading

Custom Download Templates for Easy Digital Downloads

Recently when developing a site powered by Easy Digital Downloads, I wanted one of my products to display differently from the others in the store.

When this problem arises with pages, we can easily create a page template to solve the problem. However, when it comes to creating custom templates for other items such as posts and custom post types, we need a plugin. That’s where the incredible Custom Post Template plugin by Simon Wheatley comes in. By installing the plugin you can easily create templates for your posts, but what about for downloads? Also very easy due to the extensible nature of the Custom Post Template plugin.

Continue reading

Add Image Sizes to Media Insert Dialog / Thickbox

This is such a cool little snippet. It’ll allow you to add a custom image size that you’ve added using <?php add_image_size() ?> to the media insert pop-up, so your custom image sizes can be inserted into posts as well as used through <?php the_post_thumbnail(); ?>.

Just add the following to your functions.php file:

Adjust as needed!

Hide WordPress Calendar Widget Title

When a WordPress widget has no title, the title doesn’t appear. Simple enough. However, the same doesn’t apply for the in-built Calendar widget. It will still display the title’s before and after tags regardless of the fact is doesn’t have a title.

The following little code snippet will fix that. Just add it your functions.php file:

By the way, you don’t have to have ‘bryce’ in the bit of code. Just replace it with your theme’s text domain or something else.

Custom Post Type Taxonomy ‘Type’ Breaks Media Uploader

For months, whenever one of the writers at a big WordPress site I help run (Android Australia) tried to set a featured image or insert an image into a post, they were greeted with the following:

Basically, the media library tab would acknowledge that there were X amount of images but you couldn’t actually use any of the pre-existing media. Everything would need to be uploaded again. This became very tiring and frustrating as we wanted to reuse a lot of the images already existing on the site but instead had to manually re-upload each one.

I searched long and hard and couldn’t find a solution. I asked about it, googled it and cried about it. But then one day, almost magically, I found the solution.

Continue reading