How to Conditionally Show Modules in Joomla

Tassos Marinos
Tassos Marinos
Published in Tutorials
One day ago
15 min read
Last updated one day ago
How to Conditionally Show Modules in Joomla

Joomla modules are a powerful feature for displaying content across your website, but their default visibility settings can feel limiting. While menu item assignments and access level rules offer basic control, what if you need more advanced display options? Imagine showing a module only to mobile users, displaying content exclusively on weekends, or tailoring module visibility based on a user’s geographic location. What if you could hide a module when a specific query parameter appears in the URL?

These scenarios require more than Joomla’s out-of-the-box functionality—they demand a robust solution for conditional module display. That’s where the Smile Pack’s Display Conditions feature comes in. With this powerful tool, you can unlock a new level of flexibility and personalization for your Joomla site.

This article will explore why conditional module display is essential for creating dynamic, user-focused experiences. Then, we’ll guide you through using the Smile Pack’s Display Conditions feature to take full control of your Joomla modules.

Install Smile Pack Pro

The first step to unlocking the advanced conditional module display in Joomla is to get Smile Pack Pro. Smile Pack is an all-in-one module collection designed to supercharge your Joomla site. It includes a suite of high-quality modules such as GalleryMapVideo, and PayPal, along with its standout feature: the Display Conditions. This powerful feature gives you unparalleled control over when, where, and to whom your modules are displayed.

Smile Pack - Module Collection for Joomla

With the Display Conditions tab on any module editing page, you can create highly customized module visibility rules. Here’s what you can do:

  • Add Multiple Visibility Conditions: Combine multiple conditions for complex display rules, such as showing a module only to mobile users who are new visitors and located in a specific country.
  • Chain Conditions with Logical Operators: Use AND and OR operators to fine-tune your conditions, like showing a module if a user is logged in OR accessing a specific IP address.
  • Mirror Conditions from Another Module: Copy visibility conditions from one module to another, saving time when applying the same rules across multiple modules.
  • Page-Level Targeting: Target pages more precisely using the URL, current article, or article category beyond Joomla’s menu item assignments.
  • Visitor Targeting: Target users by location, access level, device type, or whether they’re new or returning visitors.
  • Date & Time Targeting: Set visibility rules based on specific dates, times, or days of the week, perfect for promotions or seasonal content.
  • e-Commerce Conditions (HikaShop and VirtueMart): Show or hide modules based on cart totals, products added, or user shopping behaviors, enhancing the e-commerce experience.
  • Integrations with Popular Extensions: Smile Pack integrates with Joomla tools like Convert Forms, AcyMailing, EngageBox, and K2, creating advanced display rules for a seamless workflow.

Once you have purchased and installed Smile Pack Pro, follow these steps to get started:

setup conditional modules

  1. Navigate to Content -> Modules and edit the module you want to display conditionally.
  2. You should be able to see a new tab called Display Conditions. This is where you control module visibility.
  3. Set the Display Module option to Set Conditions.
  4. Choose from a variety of options to create your visibility rules.
  5. Define logic statements using AND and OR conditions to determine when the module should appear.

In the next section, we'll explore some popular use cases to help you make the most of this.

Page Based Conditional Modules

Target modules to specific pages by URL, article, or category. Display content only on relevant pages for more precise control over where your modules appear.

Hide or Show a Module in the Homepage

conditionally show a module on homepage

A common need when managing modules is controlling their visibility on the homepage. For example, you might want to hide a sidebar widget, display a welcome message only on the homepage, or show a different module on the inner pages. Joomla’s built-in Menu Assignment allows you to control this, but Smile Pack provides a simpler and more flexible approach with the Homepage Condition.

How to Set It Up:

  • Go to the Display Conditions tab.
  • Select the Homepage Condition from the list.
  • Set “Visitor is” to:
    • On Homepage” to display the module only on the homepage.
    • Not on Homepage” to display the module only on inner pages.

This method makes it easy to control module visibility without manually selecting menu items.

Show a Module to Visitors Browsing Specific Joomla Articles

show a module only on specific articles

Sometimes, you may want to display a module only on certain articles. For example, you might want to show a related products module on specific blog posts, display a call-to-action on key articles, or add extra information to selected pages. Instead of manually assigning the module to menu items, you can use the Content Article Condition for precise control.

How to Set It Up:

  • Go to the Display Conditions tab.
  • Select the Content Article Condition from the list.
  • Set “Match” to “Is”.
  • Choose the articles where you want the module to appear. You can select multiple articles.

Without Smile Pack’s Content Article Condition, assigning a module to specific articles using Joomla’s built-in settings would require creating a separate menu item for each article and selecting those menu items in the Menu Assignment tab—a tedious and time-consuming process. This condition simplifies everything, letting you choose articles directly.

Hide a Module in Articles But Show it in the Article Category View

Hide a Module in Articles But Show it in the Article Category View

If you want to show a module only on the category view and hide it on individual article pages, the Content View condition comes in handy. This is useful when you have a menu item pointing to an article category, and the module shows up on both the category and article views, but you only want it on the category view.

How to Set it Up:

  • Go to the Display Conditions tab.
  • Select the Content View condition.
  • Set the Match to ”Is Not”.
  • Choose Single Article for the content view.

This way, the module will appear in the category view but hidden on the individual article pages.

Show a Module Based on the URL Path or Query Parameters

Show a Module Based on the URL Path or Query Parameters

There are times when you might want to display a module only on specific pages based on the URL or query parameters. For instance, you might want to show a promotional banner only on certain landing pages or display a specific offer for your email newsletter based on query parameters like campaign tracking. Smile Pack makes this easy with the URL - Query String Condition, allowing you to match parts of URLs or full URLs to control module visibility. You can also use regular expressions (regex) for more advanced matching.

How to Set It Up:

  • Go to the Display Conditions tab.
  • Select the URL - Query String Condition from the list.
  • Set “Match” to “Is”.
  • Enter part of the URL or the full URL you want to match. You can add multiple items if needed.

This will ensure that the module is only shown when the visitor’s URL path or query parameters match your criteria, giving you precise control over where content is displayed.

Visitor Based Conditional Modules

Show or hide modules based on visitor attributes such as location, user group, access level, or whether they’re new or returning. Tailor content to different segments of your audience for a personalized experience.

Display a Module Only to New Visitors

Display a Module Only to New Visitors

Sometimes, you might want to show specific content or offers only to new visitors, such as a welcome message, first-time discount, or introductory offer. This can help create a more personalized experience for new users. With Smile Pack’s New vs Returning Condition, you can easily display a module only to new visitors.

How to Set It Up

  • Go to the Display Conditions tab.
  • Select the New vs Returning Condition from the list.
  • Choose “Visitor is New” to show the module only to visitors browsing your site for the first time.

Note: This condition uses cookies to determine whether the visitor is new or returning based on their previous visits to your site.

Show a Module to Users Coming from google.com

Show a Module to Users Coming from google.com

If you want to display a module specifically to visitors coming from Google, such as those arriving via a search result or ad, Smile Pack provides an easy solution using the Referrer URL Condition. This allows you to target visitors based on the site they came from, such as google.com.

How to Set It Up

  • Go to the Display Conditions tab.
  • Select the Referrer URL Condition from the list.
  • Set “Match” to “Is”.
  • Enter “google.com” to target visitors coming from Google. You can either enter the full URL or just part of it.

Note: Remember that URL Referrer discovery is not always 100% accurate. Some servers may use proxies that strip out this information, and it can be easily forged. This means that while it’s a helpful condition, it may not always be reliable.

Hide a Module from Users Located in a Specific Country

Hide a Module from Users Located in a Specific Country

There are instances when you might want to restrict content or hide a module from visitors based on their location. For example, you may want to limit access to region-specific offers, restrict content for certain countries, or show a legal notice only to visitors from certain locations. Smile Pack makes this easy with the Country Condition, allowing you to target users by country.

How to Set It Up:

  • Go to the Display Conditions tab.
  • Select the Country Condition from the list.
  • Set “Match” to “Is not”.
  • Choose the countries from which you want to hide the module. You can select multiple countries.

This will hide the module from visitors in the selected countries, ensuring that content is served only to relevant users in those locations.

Display a Module to Users Using a Mobile Device

Display a Module to Users Using a Mobile Device

In many cases, you may want to show users different content based on their device. For example, you might have a mobile-friendly version of a module, a special offer for mobile users, or a click-to-call button that makes sense only on phones. Instead of displaying the same module to all users, you can control its visibility with the Device Condition.

How to Set It Up:

  • Go to the Display Conditions tab.
  • Select the Device Condition from the list.
  • Set “Match” to “Is”.
  • Set the Device option to “Mobile” to show the module only to mobile users.

Reminder: You can also use this condition to target tablet or desktop users by selecting the corresponding option.

Note: This does not simply hide the module using CSS! It is a real visibility rule processed with server-side logic, meaning the module is completely removed from the page for devices that don’t match the condition.

Hide a Module from Users with a Specific IP Address

Hide a Module from Users with a Specific IP Address

There may be situations where you want to exclude specific users from seeing a module, such as internal staff or test users. Smile Pack’s IP Address Condition allows you to hide a module for users from specific IP addresses, giving you full control over who can see the module based on their location or network.

How to Set It Up

  • Go to the Display Conditions tab.
  • Set “Match” to “Is not”.
  • Select the IP Address Condition from the list.
  • Enter the list of IP addresses you want to exclude. You can add multiple IP addresses to target specific users.

This condition ensures that users from the specified IP addresses won’t see the module, which can be useful for internal testing or restricting access for certain users.

Show a Module based on Visitor Cookies

Show a Module based on Visitor Cookies

Suppose you want to display a module based on a user’s interaction with a site, such as showing a special offer after a user has accepted a cookie consent or visited a specific page. In that case, Smile Pack’s Cookie Condition makes it easy. By targeting users with a specific cookie value, you can control when and to whom a module is shown based on browsing behavior.

How to Set It Up

  • Go to the Display Conditions tab.
  • Select the Cookie Condition from the list.
  • Define the cookie name you want to target.
  • Set the Match to “Equals”.
  • Enter the value you want to target in the Cookie Content option.

This condition ensures the module is displayed only to users with a specific cookie value, allowing you to show targeted content based on user behavior or preferences.

Note: This condition can also be used to check whether a cookie exists, regardless of its value. In this case, simply set the match option to “Exists” to target users with the specified cookie, regardless of the content.

Date Time Based Conditional Modules

Automate module visibility based on specific dates, times, or days of the week. Schedule promotions, seasonal content, or time-limited offers to display exactly when needed, without manual intervention.

Show a Module from 10 AM to 11 AM on Weekends

Show a Module from 10 AM to 11 AM on Weekends

There are many cases where you might want to display a module only during specific hours on certain days. For example, you might have a limited-time promotion, a support chat widget with particular availability, or an event announcement that should only appear at the right time. Instead of manually enabling and disabling the module, you can automate this with Time Range and Day of Week conditions.

How to Set It Up

  • Go to the Display Conditions tab.
  • Add the Time Condition:
    • Set “Match” to “Is between
    • Set Start Time to 10:00 AM.
    • Set End Time to 11:00 AM.
  • Add the Day of Week Condition
    • Set “Match” to “Is”.
    • Set Day of Week to Weekend (Saturday and Sunday).

Under these conditions, the module will automatically appear only from 10 to 11 a.m. on Saturdays and Sundays, ensuring it’s visible exactly when needed.

e-Commerce Conditional Modules

Target users based on their cart contents, spending, or products they browse. Create personalized shopping experiences, such as promoting offers based on cart totals or product selection, and integrate with HikaShop and VirtueMart for dynamic targeting.

Display a Module if VirtueMart Cart Contains Specific Products

Display a Module if VirtueMart Cart Contains Specific Products

Suppose you want to show a module based on the products in a user’s shopping cart, such as offering a related product suggestion or special offer depending on their cart contents. In that case, Smile Pack offers a powerful solution. With the VirtueMart Products in Cart Condition, you can target specific products and set quantity thresholds to control when the module is displayed.

How to Set It Up

  • Go to the Display Conditions tab.
  • Select the VirtueMart Products in Cart Condition from the list.
  • Choose the products you want to target and set the quantity threshold for each product. You can select multiple products and define the quantity to trigger the module.

Note: This condition is also available for Hikashop stores, allowing you to target products in carts for both VirtueMart and Hikashop.

Show a Module if VirtueMart Cart Total is Below $100

Imagine a store offering various products, such as clothing and accessories, and you want to encourage customers to increase their order value by offering a free gift on purchases over $100. To promote this offer, you can use this condition to display a module reminding customers about the gift when their cart total is below $100, prompting them to add more items to qualify.

How to Set It Up

  • Go to the Display Conditions tab.
  • Select the HikaShop Amount in Cart Condition from the list.
  • Enter the cart total or subtotal threshold for which you want to trigger the module display. For example, set it to $100 to show the module when the cart total is below $100.

This condition ensures that the module is hidden from users whose cart total does not meet the specified threshold, allowing you to control visibility based on the value of the cart.

Other Cases

Show a Module When a PHP Function Returns True

Show a Module When a PHP Function Returns True

You can use the PHP Condition to execute custom PHP code to control when a module is displayed. This is especially useful when you need more complex logic and want to create unique visibility conditions not covered by the built-in options.

How to Set It Up

  • Go to the Display Conditions tab.
  • Select the PHP Condition from the list.
  • Enter your custom PHP code that returns either true or false.

Example:

// This will return true on Saturday (6) and Sunday (7)
return (date('N') >= 6); 

In this example, the module will only be shown on weekends (Saturday and Sunday). The date('N') function returns the day of the week as a number (1 for Monday through 7 for Sunday), and we check if it’s 6 or 7 (Saturday or Sunday). If the condition returns true, the module will be displayed; if false, it will be hidden.

The sky is the limit here! You can use this to query the database, interact with external APIs, or implement any custom logic you need. Whether it’s checking a user’s login status, verifying their membership level, or requesting an external service, this condition provides immense flexibility for controlling module visibility based on virtually any scenario you can imagine.

The all-in-one Joomla Module Collection
The all-in-one Joomla Module Collection
Reduce extension clutter with our premium modules suite. Make modules dynamic in a just a few clicks. Personalise content with Smart Tags.
5 rate from 4 reviews