Skip to content

Instantly share code, notes, and snippets.

@scottgruber
Last active March 31, 2017 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottgruber/c5176f10eff0b213af5b1893c71c4890 to your computer and use it in GitHub Desktop.
Save scottgruber/c5176f10eff0b213af5b1893c71c4890 to your computer and use it in GitHub Desktop.
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