Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Using PerchSystem class to conditionally load MailChimp subscribe form when visitor is not on home page

Two methods using PerchSystem::get_var to test if user is on home page.

If user is not on home page, then load MailChimp subscribe form.

Use Case

I have a subscribe to my email newsletter component in the middle of my home page. I also include the subscribe component in the footer of each page. The conditionally test lets me load the subscribe component only when users are not on the home page thereby avoiding the duplication. I'm taking advantage of PerchSystem class which holds a number of utility methods to make it easier to quickly code a solution. I'm posting this note to document my use cases and learning notes PerchSystem.

Links

Utility

Utility to print available vars print_r(PerchSystem::get_vars());

Level

  • Beginner
<?php
# Method 1 using perch_page_path var.
# Advantage not tied to specific domain
$pagepath = PerchSystem::get_var('perch_page_path');
if ($pagepath !== "/") {
perch_mailchimp_form('forms/subscribe');
}
?>
<?php
# Method 2 using 'url' var
$url = PerchSystem::get_var('url');
if ($url !== "https://scottgruber.me/") {
perch_mailchimp_form('forms/subscribe');
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment