Add a newsletter popup form without using plugin (WordPress + Gravity form)

When working with WordPress sites, I always try to use as less plugins as possible, especially those that have their own styles and Javascript code, because they can be too heavy and may slow down sites. Their designs also may not match well with the overall design and colour scheme of your website. Here’s the code I usually use when creating popups for newsletter subscriptions, which will load when user first load the website. In this example I have use gravity forms. I have used cookies in this function to boost user experience. You do not want to see the same popup twice, do you?

Step 1: Amend header.php head tag (Place this before </head> tag)

This Javascript snippet will check if the ‘hide_newsletter’ cookies is stored in the browser. If it is not, it will show the popup, and then set a new cookie that expires in a year.

Step 2: Amend header.php body tag (Place this right after <body> tag)

This code snippet mainly construct the popup form using HTML. It also uses PHP to check if cookie is set.

Step 3: Update style.css

This code mainly styles the popup to suit any design!

Leave a Reply

Your email address will not be published. Required fields are marked *