Several of our clients requested that we add popup disclaimers before someone sends an email to the site admin or before they submit a comment. Here’s a screenshot of what we’re going to do:
Case 1: Add a Contact Us link to the navigation menu that triggers a disclaimer popup.
Once a visitor clicks OK, open the visitor’s email client using the mailto: function.
- In the WordPress dashboard, go to Appearance > Menus and add a custom link.
- Go to Screen Options and make sure the “CSS Classes” checbox is checked
- In the URL field, put mailto:youremail@yoursite.com
- In the CSS Class, put show-confirm-popup
- Open up header.php
- Check to see if you already have the jQuery library loaded on your site. If not, add the following somewhere between the opening and closing head tags
1<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> - Add the following code between the opening and closing head tag. Make sure to change the text of the disclaimer.
1<script type="text/javascript">$(document).ready(function(){ $('.show-confirm-popup a').each(function(){ $(this).click(showConfirmPopup); }); }); function showConfirmPopup(){ var confirmation_text = 'Change this text. By clicking "OK," you agree that you have read and understand this notice.'; return confirm(confirmation_text); } $(function(){ }); </script>
Case 2: Add the popup disclaimer to any link.
- Add the following link structure anywhere on your site.
1<a onclick="return showConfirmPopup();" href="mailto:youremail@yoursite.com">Contact Us</a>; - Copy the code from Step 6 and 7 from Case 1 above into header.php.
Case 3: Add the popup disclaimer before a comment is submitted
- Open Comments.php
- Do a search for the word “submit”
- Add the onClick parameter to the Submit button. It will look something like this:
1<input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" onClick="return showConfirmCommentPopup();" /> - Copy the code from Step 6 and 7 from Case 1 into header.php and also in header.php, add the following function. Remember to change the text.
1function showConfirmCommentPopup(){ var confirmation_text = 'Change this text. By clicking "OK," you agree that you have read and understand this notice.'; return confirm(confirmation_text); }
Big thank you to Elisha!
Pingback: Disclaimer Popups Using jQuery()
Pingback: Weekly WordPress Review » WPCanada()