Default Tab & Filter For MixItUp

Quick Summary

  • Set the load option's filter to .day1 in the mixitup() config so only day1 items show on first load and that tab appears active.
  • Each item needs MixItUp's target class, mix by default, plus a filter class such as day1, which WordPress can print from post terms.
  • controls.toggleDefault only matters with data-toggle controls and has no effect on regular data-filter buttons; define containerEl before the code runs.

MixItUp is a JavaScript library for filtering and sorting items in a grid. When the page loads, it shows all items by default. If your filter buttons work like tabs, for example one tab per event day, you usually want one tab selected and only its items visible from the start. The load option in the MixItUp config does that.

Run this in your JavaScript file after the MixItUp library has loaded and the container is in the page.

JavaScript
var mixer = mixitup(containerEl, {
            animation: {
                effects: 'fade scale(0.5)'
            },
            controls: {
                toggleDefault: 'day1'
            },
            load: {
                filter: '.day1'
            }
        });

How it works

  • containerEl is the element that holds your items, for example the result of document.querySelector(). Define it before this code runs.
  • load: { filter: '.day1' } is the key part. On first load, MixItUp shows only the items with the class day1, and the control with data-filter=".day1" is marked as active, so it looks like the open tab.
  • Each item needs MixItUp’s target class (mix by default) plus its filter class, such as day1 or day2. In a WordPress loop you can print those classes from each post’s terms, as in printing custom taxonomy term slugs as CSS classes. To make another tab the default, change .day1 to that tab’s class.
  • animation.effects sets the transition: items fade and scale to half their size as they’re hidden, and back as they’re shown.
  • controls.toggleDefault only matters when you use toggle controls (data-toggle). It sets the filter MixItUp falls back to when all toggles are switched off. With regular data-filter buttons it has no effect.
Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More