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:
I’m currently using these functions in my new builds to clean up features I don’t use:
The last function removes all block library and WooCommerce styles, as I don’t use the block editor, and style my e-commerce pages using Elementor.
The scenario is this:
The site has multiple shipping methods (multiple client locations, and the option to ship to “Other”.)
I wanted to show the address panel if “Other” location was chosen, and hide the “Ship to Another Location” option heading on the shipping page if a client location was chosen.
None of this was strictly necessary, but it makes for a smoother customer experience.
This went into my functions.php file.
Then, this is the hide_ship_to.js script file. (uploaded to the theme directory)
No need for the overhead of a plugin.
In this case, I have a custom post type for FAQs, where the title is the question, and the content is the answer.
This script hides all the answers until one of the questions is clicked.
Here’s the JavaScript:
And the HTML:
Then, this little bit of CSS brings it together:
Send a custom message to users who request a password re-set:
Prevent robot scrapers from easily finding out which version of WordPress you’re running.
Not a substitute for keeping WP updated, but a handy fallback for clients who may not.
When you are locked out of your WordPress site and have no access to PHPMyAdmin, add this to your functions.php file to create a new admin user account.
Remove it from the functions file after you’re successfully logged in. (The user will remain.)
Thanks for the snippet, WPBeginner!
When creating custom post types, you often need custom fields for them. In the past, your options were “normal” or “side” with priorities. Depending on what else is displayed on your edit screen, these boxes could vary in where they appeared.
And sometimes you just need to add a comment or note to the edit pages.
Good News! We now have new hooks to place them precisely:
Here’s an article that explains the usage: https://make.wordpress.org/core/2012/12/01/more-hooks-on-the-edit-screen/
Programmatically add an item to any menu that is called with wp_nav_menu.
Thanks, Micah Wood! https://gist.github.com/wpscholar/1249995
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: