This is a personal collection of snippets I use on client sites. Some are original, some highly modified or cobbled together from other sources, and some copied (only from open sources such as this.)
I generally prefer not to use plugins for simple features and functions, especially if my clients don’t need options, which is quite often the case.
Free support for these snippets is probably not an option for your unique applications, due to my work load, but it never hurts to ask.
Copy, share and code on!
The Issue:
I have a calculated column in a table, and the first cell in the column needs to be unique.
Why? The column is essentially a running total.
The first cell, though needs to start with an existing balance – from another cell.
Here’s an example:
|
A |
B |
1 |
amount |
total |
2 |
5 |
7 |
3 |
3 |
10 |
So, cells in column A are entered by the user.
The formula for cell B2 is =B2+{number from another cell}
The formula for cell B3 is =B3+B2.
The issue is that when I add another row, the formula in B4 will be the same as B2, due to the way Excel assigns default formulas.
And my extensive search turned up nothing reasonably simple.
Here’s my solution: (yes, it’s kind of a hack, but it works)
|
A |
B |
C |
1 |
row |
amount |
total |
2 |
2 |
5 |
7 |
3 |
3 |
3 |
10 |
So, the formula for Column A is: =ROW(), which just outputs the row number.
The formula for column C is: =IF(A2=2, C2+{number}, C2+C1)
A simple IF statement – if it’s row 2, use the first formula. Otherwise, use the second.
Voila!
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.
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.
Forget complicated plugins with tons of options you don’t need.
Easily create a floating button on your site with this simple CSS:
Then just add this anywhere on your page or template:
In this example, I used the class ‘button’ because the styling for that is already in my theme. You can remove that class and add the styles in the CSS above if you like.
I needed to pass a hash, and scroll to the matching anchor on a new page.
Not as easy as it sounds in WordPress. (Pretty permalinks make it not work.)
After much testing and research, here’s the solution that worked best:
I added the “-150” after the offset to show the header above the anchor.
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)
To add an icon using only CSS (for example, before list items), use this code:
Of course, you’ll need to have the FontAwesome font installed on your site.
Get the unicodes for icons here: http://fontawesome.io/cheatsheet/
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: