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 in its body and add the images you want to have in it, this will also increase your site SEO value. 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:
add_theme_support( ‘post-formats’, array(
‘aside’, ‘gallery’
) );
Now, whenever you start a new post, you have an option to choose a gallery format. Do so and add theshortcode 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.