How to only display one category in a WordPress gallery with multiple categories

In this tutorial, first we will learn how to create a WordPress gallery with multiple categories. A demo created with the tutorial is as follows: WordPress Gallery with Category Filter. You can click the category buttons on top of the WordPress gallery to show different categories.

In some cases, you may want to add the same WordPress gallery to other webpages, but only want to display one of the category. In the second part of the tutorial, we will learn how to only display one of the categories by using gallery shortcode attributes.

There are 3 steps in this tutorial:

  • Step 1 - Install Wonder Grid Gallery
  • Step 2 - Create a WordPress gallery with multiple categories
  • Step 3 - Only display one of the categories by using gallery shortcode attributes

Step 1 - Install Wonder Grid Gallery

First please install the plugin Wonder Grid Gallery. You can download the free version from the plugin home page, test it, make sure it works for you before upgrading to the commercial version.

Step 2 - Create a WordPress gallery with multiple categories

In this step, please view the tutorial to create a WordPress gallery with multiple categories: How to create a WordPress gallery with categories.

You can click the link to view the demo created with the tutorial: WordPress Gallery with Category Filter.

Step 3 - Only display one of the categories by using gallery shortcode attributes

To only display one of the categories in the WordPress gallery, when adding the gallery to a WordPress page or post, change the WordPress gallery shortcode to the follows:

[[wonderplugin_gridgallery id=1 data-categorydefault="CATEGORYSLUG" data-categoryshow="false" data-deferloading="true"]]

The attribute data-categorydefault="CATEGORYSLUG" will change the specified category to the default category of the gallery. Please make sure to change CATEGORYSLUG to the slug of your own gallery category.

The attribute data-categoryshow="false" hides the category buttons or selection so the visitor can not switch to other categories. You can change the value to true if you still want to display the category buttons.

The attribute data-deferloading="true" tells the gallery not to load the hidden categories on page load.

A demo is as follows. It's the same gallery as the one on the page WordPress Gallery with Category Filter, but we have used the above shortcode attributes to only the show the Video category.