Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Popup Maker Custom Trigger PHP Function for Loading a Popup Based URL contains using the ATC extension
<?php // Ignore this first line when copying to your child theme's functions.php file.
* This PHP function will load a popup on a post or page only if the URL
* contains the word "test" in it.
* Usage:
* 1) Install the Popup Maker Advanced Targeting Conditions extension.
* 2) Edit a popup.
* 3) Go to Popup Settings > Targeting.
* 4) Select Custom PHP Function and enter custom_url_contains_condition as the function name.
* 5) Click Publish or Update to save your changes.
* API calls:
* 1) pum_get_popup_id
* 2) PUM_Site_Popups::preload_popup_by_id_if_enabled
function custom_url_contains_condition() {
global $wp;
if ( !str_contains( home_url( $wp->request ), 'test' ) ) return; // Only enable the popup if the URL has test in it. Change test to what you want.
PUM_Site_Popups::preload_popup_by_id_if_enabled( pum_get_popup_id() );
* You can add the PHP code snippet to your child theme's functions.php file
* or with third-party plugins such as My Custom Functions and Code Snippets.
* Learn more:
* -
* -
Copy link

marklchaves commented Sep 30, 2022

Screen capture of the Targeting condition


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment