WordPress theme gallery

Adding a Simple Gallery to Your WordPress Theme Without a Plugin

The gallery shortcode allows you to add a new gallery to your WordPress site’s page or post. However, you often need to style it in a certain way so that it inherits the styles of your existing theme to ensure better user experience. The following code snippet does just that and adds a pleasant hover effect to the pictures in your gallery:

Just add the code above to the stylesheet of your theme and make a new page in your WP dashboard. Then insert the shortcode [gallery] in its body and add the images you want to have in it. Click here to see a live example. Of course, your theme will be using a different color scheme and you might need to change a color or two.

If you want your theme to support the gallery post format, you should add the ‘gallery’ format to the add_theme_support function in your functions.php file like this:

Now, whenever you start a new post, you have an option to choose a gallery format. Do so and add the [gallery] shortcode to the body of the post as you did before with the page. Publish the post and it will be automatically populated with a gallery of images.

Leave a Reply

Your email address will not be published. Required fields are marked *