Gravity Form Email Validation by Domain

November 17, 2022 (1 year ago)
Functions, PHP, WordPress

Scenario:

Needed to allow ONLY email addresses from a specific client domain to be entered into a Gravity Form.

NOTES: Form ID = 2, Field ID = 9
Used strtoupper to allow domain.com as well as DOMAIN.COM.

Here’s the validation script:

 

Display ACF repeater field

August 30, 2021 (3 years ago)
Elementor, PHP, WordPress

Advanced Custom Fields Repeaters are infinitely useful, but notoriously hard to display. Many plugins and page builders that allow ACF fields don’t support repeaters.

Faced with having to install and support a reasonably complex plugin only for this one feature, I wrote a shortcode to simply display the fields. It’s pretty simple, and this repeater only has one field.

To display this repeater in Elementor, use the shortcode widget, and enter: [show-required]
It can also be used anywhere else shortcodes are allowed.

Change the Text of Reset Password Email

September 25, 2016 (8 years ago)
Functions, PHP, WordPress

Send a custom message to users who request a password re-set:

 

Debugging Scripts in the Console

June 29, 2015 (9 years ago)
Functions, PHP

The easiest way to see what data is being used inside a script. Add this script to your page (or in functions.php for sitewide use).

Then call it inside your function like this:

Then just look at your console log to see the output.

Hint: if you are tracking one variable through a script and want to see how it changes, try something like this:

 

Embedding a Video in a Template File

January 11, 2015 (9 years ago)
PHP, WordPress

Adding shortcodes to template files is a bit tricky. Although [ embed]myvideourl[ /embed] looks like a regular WP shortcode, it’s not handled the same way.

It works just as expected in a content block, but not so in a template file. Here’s the code to embed into the template:

 NOTE: To use this code, you will need to remove the spaces inside the brackets before ’embed’ and ‘/embed’.

Allow HTML in Excerpts

December 9, 2014 (9 years ago)
Functions, PHP, WordPress

By default, WordPress strips all HTML tags from excerpts. To allow them, simply replace the filter that creates the excerpt from your content.

First, copy the default excerpt filter from wp-includes/formatting.php:

 By changing the strip_tags parameters, you can allow whatever tags you want:

Also be sure to change the name of the function. Copy this to your functions.php file.

 Then, replace the default filter with your new one in functions.php:

 

Custom Post Type for a Menu

August 29, 2014 (10 years ago)
PHP, Plugins

I created this simple plugin for a restaurant to post their menu online.

Here’s the plugin file (put in plugins directory).

It includes categories (for menu sections), and several parameters for each item.

Now here’s the menu category display page. Create a page named “archive-grille_menu.php” and upload to your theme directory. Replace the loop with this code:

(I listed the categories in two columns.)

 Next is the display page for each category:

Remember to change the divs and styling to match your page layout.

 You can see this plugin in action at: http://paradisegrille.net.

 

 

Social Share Buttons Without a Plugin

July 1, 2014 (10 years ago)
PHP, WordPress

Most sharing plugins are too loaded with options, and tend to slow down my sites.

I wrote this simple script to counter that.

Create this file and name it “sharebuttons.php”. Upload it to your theme directory.

You will also need to create your images, and style the div as you like.

 Then, to add the div to pages or posts, just put this in your template file, immediately following (or just before) the_content() — or wherever you want the buttons to appear:

Custom Admin Page

July 1, 2014 (10 years ago)
Functions, PHP, WordPress

I use these for those occasions when I need to store specialized information in non-WordPress tables. (Such as orders in a custom shopping cart I built.)

It’s also handy for adding informational or instructional pages to the Dashboard.

This adds the page to the WP admin menu (put in your functions.php file):

 The page itself ( lt_orders.php ) resides in the theme folder, and is a simple PHP page, with any functionality you like. It doesn’t need any header or footer calls because it is rendered inside the admin.

Front End Login Form

June 20, 2014 (10 years ago)
Functions, PHP, WordPress

So many times clients (and their members) want to login on the front end. Simple to add this in the header, or sidebar. Style as you wish.

Put this in your header template (or anywhere else you want the form to appear.)

 

Next »