Create a gist now

Instantly share code, notes, and snippets.

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.



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


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