You're browsing the category: Tutorials

Tutorials and snippets related to programming: Wordpress, HTML, CSS, jQuery, you name it.


Javascript: Random Image Generator

I wrote a tutorial on generating random links with javascript some months ago. Recently, a person requested to show how to show this method but with images. This is why I’m writing this tutorial about how to create a random image generator.

The first thing you need to do is create an array with the URLs of the images you’re going to use. There are two common ways to do this, as you saw on the random link tutorial.

The condensed array:

Or the regular array:

You can use any of these two methods. The next step is to create the function that will generate the images using a native random method.

And that’s it! All that’s left for you to do is to combine all the code (showed below), which would display the image and every time you refresh the page, a random image from your array will appear.


Here’s the complete code:


If you have any questions, don’t hesitate to leave a comment.



PHP: Automatic Copyright Year

In website footers, we usually use some kind of copyright notice. Something like: “© 2013”. In some cases, it may be tedious or we may forget to update this information, especially when updating website designs. The following snippets will help you have a more automatic function of displaying the year.

Add the snippets to the file where you have your copyright notice, it’s usually in footer.php.

If you want to show the current year only:

If you want to show the starting year to the current year:

There’s a function (that validates the information) that you can use to achieve the same information above:

Using the function:

It would display as: © 2013.

It would display as: © 2010 – 2013

Hope these snippets are useful, if you have questions, don’t hesitate to leave a comment or contact me and I’ll get back to you as soon as I can!

Follow @_NicoleJeanette