We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

How to Limit the number of visible gallery images in the post

  • #10936
    Avatar photo[anonymous]


    For a project, I need to add a dozen images to the gallery but I’d like to display 4 or 5 in the post and have the others only visible when the gallery is opened. Do you have any ideas on how to do this?

    Thank you in advance,

    Avatar photoBob

    You can achieve this using CSS. While it might not be the most SEO-friendly solution, it is, in my opinion, the simplest and quickest one. If you want to display 4 or 5 items, simply adjust the number in the brackets to (-n+4) or (-n+5) accordingly.

    /* Initially hide all gallery items */
    .gallery__item {
      display: none;
    /* Display only the first three gallery items */
    .gallery__item:nth-of-type(-n+3) {
      display: block;